[Haskell-cafe] Why does the transformers/mtl 'Error' class exist?

Henning Thielemann schlepptop at henning-thielemann.de
Sat Apr 17 17:52:46 EDT 2010


Ryan Ingram schrieb:
> It's used in the implementation of "fail" for those monads.
>
> class Monad m where
>    ...
>    fail :: String -> m a
>    fail = error  -- default implementation
>
> which is then used to desugar do-notation when pattern matching fails:
>
>     do
>         Left x <- something
>         return x
> =>
>      something >>= \v -> case v of { Left x -> return x ; _ -> fail
> "Pattern match failure ..." }
>
> You can argue about whether "fail" belongs in Monad (and many people
> have), but that's why it is how it is.
>   
I also prefered to not support the fail method in this way and wrote:
  
http://hackage.haskell.org/packages/archive/explicit-exception/0.1.4/doc/html/Control-Monad-Exception-Synchronous.html



More information about the Haskell-Cafe mailing list