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

Ross Paterson ross at soi.city.ac.uk
Sun May 25 07:49:29 EDT 2008

On Sat, May 24, 2008 at 09:23:10PM -0400, Dan Doel wrote:
> On Saturday 24 May 2008, Twan van Laarhoven wrote:
> > To retain most of the convenience I would propose we use MonadPlus instead,
> > which is arguably where fail should have been put in the first place (*).
> >
> > (*) Actually in a superclass MonadZero, but let's work with what we have
> This is where I'd cast my vote, as well. MonadPlus is, currently, the proper 
> generalization of Maybe's safe failure behavior. We should use it.
> I don't see how specializing to Maybe and requiring people to explicitly 
> inject into an arbitrary MonadPlus gains anything over restricting to 
> MonadPlus in the first place.

What it gains is safety: with Maybe you know what you're getting, while
with a class it depends on how the instance was defined.

I'm not sure whether those arguing for MonadPlus are suggesting that
these functions should use fail or mzero to signal failure.  If fail,
there will be instances that implement it using error or an exception.
If mzero, there's less gained over Maybe, but still no guarantee of

More information about the Libraries mailing list