HaskellWiki

Haskell | Wiki community | Recent changes
Random page | Special pages

 

Not logged in
Log in | Help

Request an account if you don't have one.

MonadPlus

Categories: Standard classes

MonadPlus class (base)
import Control.Monad

The MonadPlus class is defined like this:

class (Monad m) => MonadPlus m where
   mzero :: m a
   mplus :: m a -> m a -> m a

The precise set of rules that MonadPlus should obey is not agreed upon.

mplus mzero a = a
mplus a mzero = a
mplus (mplus a b) c = mplus a (mplus b c)
mzero >>= k = mzero
mplus a b >>= k = mplus (a >>= k) (b >>= k)
mplus (return a) b = return a

1 Which satisfies what?

[] satisfies Monoid, Left Zero, and Left Distribution.

Maybe, IO and STM satisfy Monoid, Left Zero, and Left Catch.

2 Which rules?

Martin & Gibbons choose Monoid, Left Zero, and Left Distribution. This makes [] a MonadPlus, but not Maybe or IO.

3 What should be done?

It is proposed that the class be separated into MonadZero, MonadPlus, MonadOr. See MonadPlus reform proposal.

Retrieved from "http://haskell.cs.yale.edu/haskellwiki/MonadPlus"

This page has been accessed 4,052 times. This page was last modified 02:40, 31 July 2008. Recent content is available under a simple permissive license.