
25 May
2010
25 May
'10
9:52 a.m.
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)