
17 Apr
2010
17 Apr
'10
5:52 p.m.
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/htm...