Functor . Haskell

Haskell class

-- definition
class Functor f where
    fmap :: (a -> b) -> f a -> f b
 
-- methods
    (<$) :: a -> f b -> f a
    (<$) = fmap . const
fmap id $\ \leftrightsquigarrow\ $ id
fmap f . fmap g $\ \leftrightsquigarrow\ $ fmap (f . g)

Discussion

In Haskell, the first law implies the second.

Notes

Reference


Haskell, Functor, Functor category