[Haskell-beginners] MonadPlus

Johann Bach johann.bach1127 at gmail.com
Wed Jul 28 15:56:58 EDT 2010


On Wed, Jul 28, 2010 at 3:51 AM, Brent Yorgey <byorgey at seas.upenn.edu> wrote:
> 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

Brent -- also, in his example (similar to my example above) it looks
like the only benefit of the list instance of MonadPlus in this case
is to use the pre-existing definition of guard. Is that true? His
example is indeed more complex... it's in TMR issue 11.

-Johann


More information about the Beginners mailing list