[Haskell-cafe] Stacking monads
Henning Thielemann
lemming at henning-thielemann.de
Sun Oct 5 13:50:17 EDT 2008
On Thu, 2 Oct 2008, Andrew Coppin wrote:
> Consider the following beautiful code:
>
> run :: State -> Foo -> ResultSet State
>
> run_and :: State -> Foo -> Foo -> ResultSet State
> run_and s0 x y = do
> s1 <- run s0 x
> s2 <- run s1 y
> return s2
>
> run_or :: State -> Foo -> Foo -> ResultSet State
> run_or s0 x y = merge (run s0 x) (run s0 y)
>
> That works great. Unfortunately, I made some alterations to the
> functionallity the program has, and now it is actually possible for 'run' to
> fail. When this happens, a problem should be reported to the user. (By "user"
> I mean "the person running my compiled application".) After an insane amount
> of time making my head hurt, I disocvered that the type "Either ErrorType
> (ResultSet State)" is actually a monad. (Or rather, a monad within a monad.)
> Unfortunately, this causes some pretty serious problems:
>
> run :: State -> Foo -> Either ErrorType (ResultSet State)
You may also like to use:
http://hackage.haskell.org/packages/archive/explicit-exception/0.0.1/doc/html/Control-Monad-Exception-Synchronous.html
More information about the Haskell-Cafe
mailing list