Answers
- A functor is a type constructor,
f
, with an instance of theFunctor
type class:class Functor f where fmap :: (a -> b) -> (f a -> f b) (<$) :: b -> (f a -> f b) x <$ t = fmap (\_ -> x) t
This is subject to the identity and fusion laws:
fmap id = id fmap f . fmap g = fmap (f . g)
- An applicative functor,
f
, is a functor with an instance of theApplicative
type class:class Functor f => Applicative f where pure :: a -> f a (<*>) :: f (a -> b) -> f a -> f b fs <*> xs = liftA2 ($) fs xs liftA2 :: (a -> b -> c) -> f a -> f b -> f c liftA2 f xs ys = fmap f xs <*> ys (*>) :: f a -> f b -> f b xs *> ys = liftA2 (\_ y -> y) xs ys (<*) :: f a -> f b -> f a xs <* ys = liftA2 (\x _ -> x) xs ys
This is subject to four laws:
pure id <*> v...