[Haskell-cafe] ErrorT vs Either
aslatter at gmail.com
Mon May 16 23:55:56 CEST 2011
On Mon, May 16, 2011 at 4:41 PM, Gracjan Polak <gracjanpolak at gmail.com> wrote:
> Thanks Daniel, Yves and Edward for explanation. Two things come to my mind now.
> 1. It should be unified. Why? Because conceptually:
> runIdentity (runErrorT (fail "msg")) :: Either String Int
> Left "msg"
> fail "msg" :: Either String Int
> *** Exception: msg
> Should be the same as Identity monad should not add structure.
ErrorT and Either are different types - I think it is okay that they
In some applications you might not want to silently discard pattern
> 2. I need a Failure monad that works well with pattern match failures (that call
> fail). I'd like to use it like this:
> runErrorT $ do
> Active <- getStatus -- ensure proper status
> Just elm <- lookup stuff there -- lookup element
> when (condition) $ fail "wrong!" -- check condition
> return 1234 -- return useful value
> sort of... Any ideas what could be used in place of Either monad? Basically I
> need working pattern match failures (I guess that means I need working fail
> method that is not equal to error).
ErrorT is a good choice for this.
There is also the 'ExceptionT' monad transformer over here:
Which you'll want to use with the exception-mtl package
I don't have any experience with it, but from what I can tell those
are the two choices already built.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe