#2309: containers: specialize functions that fail in a Monad to Maybe

Ross Paterson ross at soi.city.ac.uk
Tue May 27 17:57:50 EDT 2008


On Sun, May 25, 2008 at 07:58:44AM -0400, Dan Doel wrote:
> I don't think we should get rid of fail. There's nothing wrong with it, per 
> se. It just shouldn't be in Monad, it should be in MonadPlus (or MonadZero if 
> things get split back up 1.4 style). fail is mzero that takes a string to 
> explain what happened.

No, it's a different value: one can write programs that distinguish them.
Haskell 98 treats error "string" as _|_ only because it can't analyse _|_.

> [...]  The problem is calling fail in monads 
> that don't have an mzero, because they don't have a notion of failure.

That is indeed part of the problem, because someone will define an
instance for those monads, for the sake of convenience.

> I didn't mean to say that Maybe is arbitrary. I meant that specializing to 
> Maybe makes it more inconvenient to use with other MonadPlus instances, and I 
> don't see a benefit to counter that.

There is a choice here between convenience and safety.  What would
Haskell choose?

> [...]
> That's not to mention potential information loss compared to fail.

which does not arise in this particular case.

> [...]
> I just think it's frustrating that we have abstractions that do exactly what 
> we want, and then don't use them. :)

It's not an abstraction: it's overloading.  It conflates three different
things (an element of a view, exceptions and runtime errors).


More information about the Libraries mailing list