Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7401471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:28:34+00:00 2026-05-29T04:28:34+00:00

I want a State monad where fail modifies the state rather than throwing an

  • 0

I want a State monad where fail modifies the state rather than throwing an exception. Failure early in such an action should also skip any later actions.

For example, the following should produce "FAILED: foo" as the final state:

execState (fail "foo") ""

this should produce the same result

execState (fail "foo" >> put "hi") ""

Using the standard State monad, the former throws an exception and the latter produces "hi"

I assume there’s some clever way to use StateT to make my own monad with this behavior, but haven’t figured it out yet. What’s a good way to accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:28:35+00:00Added an answer on May 29, 2026 at 4:28 am

    You can try using StateT applied to ErrorT (though you may need the strict variant of StateT to get your desired behaviour). Here, the fail call gets thrown down the stack into the next monad.

    However, if you actually want it as part of the internal state rather than the stack, writing your own State-like monad is probably the way to go, using Either internally. For example, see how polyparse has a stateful parser with an internal datatype that records whether a failure has occurred or not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a state monad such as: data Registers = Reg {...} data
I want to maintain state in my Perl web app. How can I do
I want to ensure that a WCF-ServiceClient State will be closed after using the
I want to check some things about the state of the session, the user
I want to write a ViewModel that always knows the current state of some
If I want to navigate directly to the second state of some flex app,
I want to set the thumb image of a slider for a normal state,
I have a Seekbar and I want to save the state to database when
I have a range named STATE. I want to set data validation in range
I have a Python application in a strange state. I don't want to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.