Functor

We have seen how map is defined for [], and we can also map on other types. We call these types Functor if they can be mapped and can satistify the Functor law at the same time.

Functor laws: map id = id | map (compose g f) = map g . map f

  1. class Functor f where
  2. map :: forall a b. (a -> b) -> f a -> f b
  3. instance Functor Maybe where
  4. map f (Just x) = Just (f x)
  5. map f Nothing = Nothing