[Haskell-cafe] Re: What are the MonadPlus laws?

David Menendez zednenem at psualum.com
Wed Jan 26 00:57:33 EST 2005


Ashley Yakeley writes:

> In article <F9A40F60-6EFD-11D9-8550-000A95F0ED78 at jellybean.co.uk>,
>  Jules Bean <jules at jellybean.co.uk> wrote:
> 
> > So, anyone? What are the laws that MonadPlus is supposed to satisfy?
> 
> These are what I think they should be:
> 
>   mplus mzero a = a
>   mplus a mzero = a
>   mplus (mplus a b) c = mplus a (mplus b c)
>   mzero >>= a = mzero
>   (mplus a b) >>= c = mplus (a >>= c) (b >>= c)
> 
> These are what is found in Martin and Gibbons paper, even as they're 
> wrong that Maybe can follow them.
> 
>
<http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/
tactics
> ..pdf>
> 

Philip Wadler listed those as the laws he "would usually insist on" in a
1997 message[1].

    [1] <http://www.dcs.gla.ac.uk/mail-www/haskell/msg00057.html>

He also mentions two other possible, but problematic, laws:

    m >>= \x -> mzero           == mzero
    m >>= \x -> k x `mplus` h x == m >>= k `mplus` m >>= h

The first doesn't hold when m is bottom. The second doesn't hold for
lists.

-- 
David Menendez <zednenem at psualum.com> <http://www.eyrie.org/~zednenem/>


More information about the Haskell-Cafe mailing list