Search code examples
haskellcategory-theory

In Haskell, is the map function a functor?


The type of map is: (a->b) -> [a] -> [b]

while the type of the functor fmap is:

Functor f => (a+b) -> f a -> f b I read on wikipedia that map was a polymorphic morphism while fmap was a polytypic morphism but that doesn't really clear up things for me.

So my question is: is the map function a functor?


Solution

  • In Haskell terms, fmap is a method in the typeclass Functor, not the functor itself. [], Maybe, ... are type constructors which instantiates the class Functor and, abusing the language, you can say that "Maybe is a functor".

    In mathematical terms, a functor (or more specifically in this case, an endofunctor in the category Hask, the category of Haskell types) is composed of two mappings: the first one from a type to another and the second from an arrow (a -> b) to another (f a -> f b) which preserves the structure. In that sense, Maybe is the first arrow which maps a type to another, say Int to Maybe Int and the fmap for Maybe is the second arrow.