derek.a.elkins at gmail.com
Fri May 9 16:09:36 EDT 2008
On Fri, 2008-05-09 at 12:47 -0700, David Roundy wrote:
> 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).
MonadPlus is a crude way of doing that, but that isn't the motivating
example of MonadPlus, indeed, that arguably shouldn't be a MonadPlus
instance. Cale Gibbard suggests (perhaps not originally) splitting
MonadPlus into MonadPlus (and MonadZero) and MonadOrElse. They'd have
essentially the same operations, but would be intended to satisfy
different laws. Maybe, Either e, IO are better instances of MonadOrElse
while , Parser, LogicT, other non-determinism, parser, or concurrency
monads would more appropriately be MonadPlus.
More information about the Haskell-Cafe