[Haskell-cafe] MonadPlus

David Roundy droundy at darcs.net
Fri May 9 15:47:32 EDT 2008


On Fri, May 09, 2008 at 08:39:38PM +0100, Andrew Coppin wrote:
> OK, so I feel I understand monads fine. I regularly use Maybe, [] and 
> IO, and I've even constructed a few monads of my own. But here's a 
> question: what is the purpose of the MonadPlus class?
> 
> Clearly it defines a binary operation over monadic values and an 
> identity element for that operation. But... what is this supposed to 
> *do*? (For example, (>>) has an almost identical signature to mplus. But 
> presumably they don't both do the same thing...) What functionallity is 
> this supposed to give you?

MonadPlus is a crude way of achieving the catching of exceptional cases,
and you should think of mplus as being equivalent to (catch . const).  The
trouble is that MonadPlus doesn't provide any mechanism for finding out
what went wrong, so I've only ever found it useful when using the Maybe
monad (which itself has no way of identifying what went wrong).

> [In a somewhat unrelated question... I saw some code the other day that 
> used Either as if it were a monad. And yet, I don't see an instance 
> given in the standard libraries - even though there should be one. I can 
> see Functor (Either a), but not Monad (Either a) or even Monad (Either 
> String)...]

I am pretty certain that there is a monad instance for Either, but also
don't know where it's defined.
-- 
David Roundy
Department of Physics
Oregon State University


More information about the Haskell-Cafe mailing list