[Haskell-cafe] What are the MonadPlus laws?
Paul Hudak
paul.hudak at yale.edu
Tue Jan 25 14:00:38 EST 2005
I believe that these are the relevant laws of class MonadPlus:
m >>= (\x -> mzero) = mzero
mzero >>= m = mzero
m `mplus` mzero = m
mzero `mplus` m = m
You can get some intuition for this by thinking of mplus as +, mzero as
0, and >>= as multiplication.
I haven't follow much at all of this thread, but, for what it's worth,
IO should NOT be instance of MonadPlus, because it has no zero element.
For if it did, the IO action:
putStr "hello" >> mzero
would not print "hello", which is counterintuitive, and in practice I
wouldn't know how to implement it.
-Paul
P.S. All of the above is in my book :-)
Jules Bean wrote:
> So, anyone? What are the laws that MonadPlus is supposed to satisfy?
>
> The obvious ones are that if MonadPlus m then for all types a, (m a)
> should be a monoid. But, what about the others, because IO does not
> appear to satisfy
>
> a >> mzero == mzero
>
> Jules
More information about the Haskell-Cafe
mailing list