incorrect MonadPlus law "v >> mzero = mzero"?

John Lato jwlato at gmail.com
Thu Feb 6 01:38:35 UTC 2014


On Wed, Feb 5, 2014 at 5:01 PM, wren ng thornton
<winterkoninkje at gmail.com>wrote:

> On Wed, Feb 5, 2014 at 7:59 PM, wren ng thornton
> <winterkoninkje at gmail.com> wrote:
> > The rules I'd expect MonadPlus to obey are:
> >
> >     mzero >>= f    =    mzero
> >
> >     (x `mplus` y) >> mzero    =    (x >> mzero) `mplus` (y >> mzero)
>
> Er, sorry, that should've been:
>
>     (x `mplus` y) >> z    =    (x >> z) `mplus` (y >> z)
>
> from which the above instance follows trivially.


I don't think this is correct. consider the original instance with x /=
mzero.  Then we have

left side
(x `mplus` y) >> mzero
x >> mzero                   -- by def. of mplus

right side
(x >> mzero) `mplus` (y >> mzero)
mzero'x `mplus` (y >> mzero)           -- mzero'x is a zero with x's
effects, this reduction comes from the monad laws
(y >> mzero)                                   -- by mplus

Or concretely,

> let x = lift (print "x!") :: MaybeT IO ()
> let y = lift (print "y!") :: MaybeT IO ()
> runMaybeT $ (x `mplus` y) >> mzero

"x!"
Nothing

> runMaybeT $ (x >> mzero) `mplus` (y >> mzero)

"x!"
"y!"
Nothing

John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20140205/2f5fb3a6/attachment.html>


More information about the Libraries mailing list