[Haskell-cafe] error vs. MonadError vs. fail

Daniel McAllansmith dagda at xtra.co.nz
Tue Mar 28 17:31:52 EST 2006

On Wednesday 29 March 2006 09:49, Andrew Pimlott wrote:
> If you want to write a MonadError operation that can be used with Maybe
> or Either, it would look like
>     f :: (MonadError e m, Error e) => Bool -> m Int
>     f b = if b
>         then return 42
>         else throwError (strMsg "The boolean was false.")

As long as you're happy only using Strings for your error constructs.
Or you're willing to write a global construct<->String codec across all error 
constructs.  Doesn't sound very pleasant to me.

> But I see your point now about MonadFail (having throw but not catch)
> being perhaps preferable for this use.

My intuition is that you'd want three error related monads, Fail, Catch and 
Convert, to achieve what I'm after... don't know if that's a good intuition 
or not. :)


More information about the Haskell-Cafe mailing list