[Haskell-cafe] What is MonadPlus good for?

Josef Svenningsson josef.svenningsson at gmail.com
Sun Feb 13 18:37:50 EST 2005


On Sun, 13 Feb 2005 17:59:57 -0500, ajb at spamcop.net <ajb at spamcop.net> wrote:
> G'day all.
> 
> Quoting Remi Turk <rturk at science.uva.nl>:
> 
> > According to http://www.haskell.org/hawiki/MonadPlus (see also
> > the recent thread about MonadPlus) a MonadPlus instance
> > should obey m >> mzero === mzero, which IO doesn't. IOW, the
> > MonadPlus instance for IO (defined in Control.Monad.Error)
> > probably shouldn't be there.
> 
> Clearly the wiki page has not been updated to reflect the current
> debate. :-)
> 
> I've changed the wording to this.  Anyone disagree?
> 
>     Note: There are theoretical reasons why ''mzero'' should be a
>     right-zero for (>>=), but surprisingly few of the existing MonadPlus
>     instances actually obey this law.  {{{IO}}} does not, and neither do
>     any ["MonadTransformer"]s, since they may be stacked on top of {{{IO}}}.
>     This suggests that either some of the extant MonadPlus instances are
>     inappropriate, or that the law itself might be incorrect.  There is
>     continuing debate over this, and the dust has not yet settled.
> 
I think it's unfair to the monad transformers to simply say that they
don't obey the law. The interesting thing is whether they *preserve*
the law. A monad transformer T preserves a law if given a monad M
which obeys the law holds then the monad T M obeys the law. I haven't
checked if this is the case for any of the monad transformers in the
hierarchical libraries though. But I think that the wording should be
changed so that they aren't blamed for breaking the law.

(I can't believe I'm taking sides with monad transformers as if they
where human. I spend too much time hacking haskell I guess...)

/Josef


More information about the Haskell-Cafe mailing list