proposal #4095: add Applicative instance for Either
Ross Paterson
ross at soi.city.ac.uk
Tue May 25 09:52:45 EDT 2010
On Tue, May 25, 2010 at 03:15:57PM +0200, Henning Thielemann wrote:
> On Tue, 25 May 2010, Ross Paterson wrote:
>
> >The proposal is to add this instance to Control.Applicative:
> >
> > instance Applicative (Either e) where
> > pure = Right
> > Left e <*> _ = Left e
> > Right f <*> r = fmap f r
> >
> >This is not the only possible instance for Either, but this one is
> >compatible with the usual Monad instance.
>
> What other sensible instances are there?
The "all errors" instance:
instance Monoid e => Applicative (Either e) where
pure = Right
Left e1 <*> Left e2 = Left (e1 `mappend` e2)
Left e1 <*> Right _ = Left e1
Right _ <*> Left e2 = Left e2
Right f <*> Right x = Right (f x)
More information about the Libraries
mailing list