Category theory/Functor

From HaskellWiki
Revision as of 15:12, 3 July 2007 by Jcast (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Definition of a Functor

Given that A and B are categories, a functor F:AB is a pair of mappings (Fobjects:Ob(A)Ob(B),Farrows:Ar(A)Ar(B)) (the subscripts are generally omitted in practice).

Axioms

  1. If f:AB in A, then F(f):F(A)F(B) in B
  2. If f:BC in A and g:AB in A, then F(f)F(g)=F(fg)
  3. For all objects A in A, idF(A)=F(idA)

Examples of functors

  • Free:SetMon, the functor giving the free monoid over a set
  • Free:SetGrp, the functor giving the free group over a set
  • Every monotone function is a functor, when the underlying partial orders are viewed as categories
  • Every monoid homomorphism is a functor, when the underlying monoids are viewed as categories

Functors in Haskell

Properly speaking, a functor in the category Haskell is a pair of a set-theoretic function on Haskell types and a set-theoretic function on Haskell functions satisfying the axioms. However, Haskell being a functional language, Haskellers are only interested in functors where both the object and arrow mappings can be defined and named in Haskell; this effectively restricts them to functors where the object map is a Haskell data constructor and the arrow map is a polymorphic function, the same constraints imposed by the class Functor:

class Functor f where
  fmap :: (a -> b) -> (f a -> f b)