[Haskell-cafe] MonadPlus

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Fri May 9 16:09:37 EDT 2008

On May 9, 2008, at 15:56 , Andrew Coppin wrote:

> Bryan O'Sullivan wrote:
>> Andrew Coppin wrote:
>>> But here's a
>>> question: what is the purpose of the MonadPlus class?
>> It gives you a way of working with monads as monoids.  Consider a  
>> Parsec
>> example:
>> metasyntactic = text "foo" `mplus` text "bar" `mplus` text "baz"
>> You'll get back whichever one matched, in left-to-right-order, or  
>> mzero
>> (a parse failure) if all of them fail.
> ...so it's a kind of choice operator? Run all actions until you get  
> to one that succeeds and return the result from that?

In monadic guise that's how it's usually used, yes (since monoids  
like (+) are not generally all that useful as monads; (++) (list  
monad) and (.) (Monad ((-) r)) might be, though).

brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH

More information about the Haskell-Cafe mailing list