Add default MonadPlus or Alternative method to MonadFail

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Add default MonadPlus or Alternative method to MonadFail

Baldur Blöndal
The documentation for Control.Monad.Fail notes

> If your Monad is also MonadPlus, a popular definition is
>> fail _ = mzero

This could be made a default definition for MonadPlus or Alternative

> class Monad m => MonadFail m where
>   fail :: String -> m a
>   fail = const empty
>   default fail :: Alternative m => String -> m a

This simplifies instances like [] and Maybe

> instance MonadFail []
> instance MonadFail Maybe

_______________________________________________
Libraries mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries