List und Tree sind Typ-Konstruktoren
(d. h. sie haben kind * -> *) für Collections.
fmap f m erzeugt eine strukturgleiche Collection,
bei der elementweise f angewendet wurde:
class Functor c where
fmap :: ( a -> b ) -> ( c a -> c b )
instance Functor [] where fmap = map
instance Functor Tree where fmap = tmap
weiteres Beispiel:
data Maybe a = Nothing | Just a
instance Functor Maybe where
fmap f Nothing = Nothing
fmap f (Just x) = Just (f x)