This is not the only possible instance for Either, but this one is
compatible with the usual Monad instance.
pure x = (mempty, x)
(u, f) <*> (v, x) = (u `mappend` v, f x)
pure x = (mempty, x)
(u, f) <*> (v, x) = (u `mappend` v, f x)
+instance Applicative (Either e) where
+ pure = Right
+ Left e <*> _ = Left e
+ Right f <*> r = fmap f r
+
-- new instances
newtype Const a b = Const { getConst :: a }
-- new instances
newtype Const a b = Const { getConst :: a }