[Haskell-beginners] Applicative instance for Either String
Stephen Tetley
stephen.tetley at gmail.com
Sat Jul 17 07:54:42 EDT 2010
Const has an Applicative instance that doesn't touch the "subject"
parameter i.e. the rightmost element of the type.
-- Const - drops /b/
newtype Const a b = Const a deriving (Eq,Show)
instance Functor (Const a) where
fmap f (Const a) = Const a
The applicative instance obliges the "data" i.e. the first parameter
to be an instance of Monoid:
instance Monoid a => Applicative (Const a) where
pure b = Const mzero
Const f <*> Const v = Const (f `mappend` v)
More information about the Beginners
mailing list