[Haskell-beginners] Monad transformers and MonadPlus

Brent Yorgey byorgey at seas.upenn.edu
Fri Jul 30 13:23:00 EDT 2010


On Fri, Jul 30, 2010 at 02:48:17PM +0200, Daniel Fischer wrote:
> On Friday 30 July 2010 13:56:44, Antoine Latter wrote:
> > You could always add a MondPlus instance to IO directly (or a newtype
> > wrapper).
> >
> > 'mplus' would set up exception handling and 'mzero' would through an
> > exception. You might want to limit it to a subset of exceptions, though.
> 
> Once upon a time, there was a MonadPlus instance for IO.
> However, one of the laws a MonadPlus instance should satisfy is
> 
> m >> mzero === mzero
> 
> You can't have that in IO, since there's no unPutStrLn and such.
> Therefore, the MonadPlus instance for IO was removed.

If I understand correctly, however, there is some debate over what the
"correct" laws for MonadPlus ought to be.  One can also imagine other
useful monads which satisfy other MonadPlus laws but not the one
above, such as MaybeT (State Int), in which failure short-circuits any
future modifications to the state, but does not roll back any state
modifications that may have happened up to the point of failure.

-Brent 


More information about the Beginners mailing list