proposal #4095: add Applicative instance for Either

Edward Kmett ekmett at
Wed May 26 00:20:43 EDT 2010

On Tue, May 25, 2010 at 6:34 PM, Ross Paterson <ross at> wrote:

> On Tue, May 25, 2010 at 04:55:09PM -0400, Edward Kmett wrote:
> > In my perfect world the next version of transformers would provide an
> entry in
> > Control.Monad.Instances for:
> >
> > instance Applicative (Either m)
> > instance Alternative (Either m)
> > instance Monad (Either m)
> > instance MonadPlus (Either m)
> What definition of empty/mzero do you have in mind?

Thats what I get for dashing off my response half baked. =) Upon actually
looking, the code that I have for that Applicative didn't supply an
Alternative/MonadPlus instance, since there isn't a suitable 'Default' class
that provides a single value without a full monoid, and if it existed, you'd
want to use it to support 'fail'

> > But there are quite possibly too many moving parts to make such a big
> > jump, and then you have the other bikeshedding issue of there being
> > yet another definition for Either that makes sense to default to:
> >
> > instance Monoid m => Applicative (Either m)
> > instance Monoid m => Alternative (Either m)
> > instance Monoid m => Monad (Either m)
> > instance Monoid m => MonadPlus (Either m)
> I can't think of a Monad instance that uses the Monoid constraint.
> What is the instance you mean?

The Monoid instance only exists to provide mempty to support fail, in a
manner consistent with the Alternative and MonadPlus instance as no weaker
class exists to use to obtain a Default.

Neither answer is really entirely satisfying.

-Edward Kmett
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Libraries mailing list