For as far as I understand, a functor is a mapping between two categories, for example from objects in
to objects in
where
and
are categories.
In Haskell there is Hask in which the objects are Haskell types and the morphisms are Haskell functions. However, the Functor type class has a function fmap which maps between these types (which are thus objects and not categories themselves):
fmap :: (a -> b) -> f a -> f b
f a and f b are both objects in Hask. Does this mean every instance of Functor in Haskell is an endofunctor, and if not does Functor really represent a functor?
What am I missing here? Are types also categories in Haskell?
An instance of
Functorspecifies two things: a type constructorFof kind* -> *, that is, a mapping from objects of Hask to objects of Hask, and a function of type(a -> b) -> (F a -> F b), that is, a mapping from arrows of Hask to arrows of Hask compatible with the object-mappingF. So, yes, all instances ofFunctorare endofunctors. There are several generalizations available on Hackage, e.g. Control.Categorical.Functor.