[Haskell-cafe] Fwd: incorrect MonadPlus law "v >> mzero = mzero"?
petr.mvd at gmail.com
Mon Feb 3 20:21:49 UTC 2014
Since nobody replied so far, I'm also forwarding to cafe.
---------- Forwarded message ----------
From: Petr Pudlák <petr.mvd at gmail.com>
Subject: incorrect MonadPlus law "v >> mzero = mzero"?
To: "libraries at haskell.org" <libraries at haskell.org>
this law apparently fails for a MonadPlus instance that has more than one
possible failure value. Consider:
runIdentity . runErrorT $
((ErrorT . Identity $ Left "failure") >> mzero :: ErrorT String
evaluates to `Left "failure"`, which isn't equal to ErrorT's mzero `Left
This isn't just the case of ErrorT, it fails for any MonadPlus with
multiple failure values. For example
lift (tell "foo") >> mzero :: MaybeT (Writer String) ()
is again distinct from mzero.
Actually, no monad transformer with a MonadPlus instance can satisfy the
law, because the first part in front of `>> mzero` can introduce side
effects in the underlying monad.
I'm not sure what should be the proper solution. Perhaps to change the laws
return x >> mzero = mzero
(v >> mzero) >>= f = (v >> mzero)`
That is, if an expression ends with `mzero`, it behaves like `mzero`.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe