[Haskell-beginners] MonadPlus

Brent Yorgey byorgey at seas.upenn.edu
Wed Jul 28 06:51:07 EDT 2010


On Wed, Jul 28, 2010 at 03:03:01AM -0700, Johann Bach wrote:
> I'm looking at Douglas Auclair's MonadPlus article, here
> http://www.haskell.org/sitewiki/images/6/6a/TMR-Issue11.pdf
> 
> So consider an example like
> 
> t2 = do
>   x <- [1,2,3]
>   y <- [1,2]
>   guard $ x+y > 2
>   return (x,y)
> 
> This uses the list instance of MonadPlus.
> 
> Now, Douglas is talking about his own code, not the above example, but
> his own code is similar. And he says "the entire computation is
> chained by mplus". I'm confused because I thought it was chained by
> >>=. In fact, I can't see where the above code makes use of mplus. The
> definition of "guard" uses mzero.

You are correct. That sentence is an error.  Indeed, it ought to say
"since the entire computation is chained with (>>=), a failure of one
test voids the entire branch".  This is because of the required law

  mzero >>= f  =  mzero

Chaining a bunch of computations with `mplus` would cause each to be
tried in turn until one succeeds, quite different than what Doug is
talking about in that sentence.

-Brent


More information about the Beginners mailing list