Laws for Monad and MonadPlus.

Dylan Thurston [email protected]
Tue, 13 Mar 2001 15:13:26 -0500


On Tue, Mar 13, 2001 at 04:15:31PM -0330, Theodore Norvell wrote:
> What about MonadPlus?  By analogy with semirings, I came up with:
> 
> Zero:                    mzero >>= k   =  mzero  =  p >>= (\x -> mzero)
> Identity:             p `mplus` mzero  =  p      =  mzero `mplus` p
> Commutativity:             p `mplus` q  =  q `mplus` p
> Right distributivity: (p `mplus` q) >>= k  =  (p >>= k) `mplus` (q >>= k)
> Left distributivity:  p >>= (\x->j x `mplus` k x)  =  (p >>= j) `mplus` (p >== k)
>                 [provided x is not free in j or k]
> 
> But commutativity does not hold for Maybe or [], left distributivity
> does not hold for Maybe and right distributivity does not hold for [],
> so these can't be right.

Incidentally, a Set monad seems to do better: it would satisfy all
these laws.

Best,
	Dylan