Functor

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

class Functor f where
  map :: forall a b. (a -> b) -> f a -> f b

instance Functor Maybe where
  map f (Just x) = Just (f x)
  map f  Nothing = Nothing