[Haskell-beginners] Maybe, Either

Michael Snoyman michael at snoyman.com
Tue Sep 15 18:19:53 EDT 2009


On Tue, Sep 15, 2009 at 11:49 PM, Brandon S. Allbery KF8NH <
allbery at ece.cmu.edu> wrote:

> On Sep 15, 2009, at 16:21 , Michael Snoyman wrote:
>
> On Tue, Sep 15, 2009 at 3:08 AM, Brent Yorgey <byorgey at seas.upenn.edu>wrote:
>
>> It doesn't work in *all* monads -- it only works in monads which
>> support a sensible notion of failure.  This is exactly what is
>> captured by the MonadPlus constraint on my version of mLookup.  And,
>> in fact, any monad in context of which you would want to use mLookup
>> (IO, Maybe, [], ...) are already instances of MonadPlus.
>>
>
> I'm looking at the Control.Monad documentation (
> http://hackage.haskell.org/packages/archive/base/latest/doc/html/Control-Monad.html),
> and it doesn't seem that IO is an instance of MonadPlus. I get the same
> results with a simple code check. Can you clarify? Calling lookup from IO is
> a common use case for me.
>
>
> That's a bit of stupidity I wish would be fixed; for some bizarre reason,
> the instance is in Control.Monad.Error.
>

And according to the documentation, that instance has a broken version of
mzero. So it seems the argument of use MonadPlus because fail is not always
defined properly doesn't exactly hold much water here. Can you tell me why
you would still recommend representing lookup failure with the mzero
function instead of the seemingly more aptly named and more available fail
function?

Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20090915/215e6da9/attachment.html


More information about the Beginners mailing list