# Category theory/Functor

## Definition of a Functor

Given that ${\displaystyle {\mathcal {A}}}$ and ${\displaystyle {\mathcal {B}}}$ are categories, a functor ${\displaystyle F:{\mathcal {A}}\to {\mathcal {B}}}$ is a pair of mappings ${\displaystyle (F_{objects}:\mathrm {Ob} ({\mathcal {A}})\to \mathrm {Ob} ({\mathcal {B}}),F_{arrows}:\mathrm {Ar} ({\mathcal {A}})\to \mathrm {Ar} ({\mathcal {B}}))}$ (the subscripts are generally omitted in practice).

### Axioms

1. If ${\displaystyle f:A\to B}$ in ${\displaystyle {\mathcal {A}}}$, then ${\displaystyle F(f):F(A)\to F(B)}$ in ${\displaystyle {\mathcal {B}}}$
2. If ${\displaystyle f:B\to C}$ in ${\displaystyle {\mathcal {A}}}$ and ${\displaystyle g:A\to B}$ in ${\displaystyle {\mathcal {A}}}$, then ${\displaystyle F(f)\circ F(g)=F(f\circ g)}$
3. For all objects ${\displaystyle A}$ in ${\displaystyle {\mathcal {A}}}$, ${\displaystyle id_{F(A)}=F(id_{A})}$

### Examples of functors

• ${\displaystyle \mathrm {Free} :\mathrm {Set} \to \mathrm {Mon} }$, the functor giving the free monoid over a set
• ${\displaystyle \mathrm {Free} :\mathrm {Set} \to \mathrm {Grp} }$, 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

### Functor operations

• For all categories ${\displaystyle {\mathcal {C}}}$, there is an identity functor ${\displaystyle Id_{\mathcal {C}}}$ (again, the subscript is usually ommitted) given by the rule ${\displaystyle F(a)=a}$ for all objects and arrows ${\displaystyle a}$.
• If ${\displaystyle F:{\mathcal {B}}\to {\mathcal {C}}}$ and ${\displaystyle G:{\mathcal {A}}\to {\mathcal {B}}}$, then ${\displaystyle F\circ G:{\mathcal {A}}\to {\mathcal {C}}}$, with composition defined component-wise.

These operations will be important in the definition of a monad.

### The category Cat

The existence of identity and composition functors implies that, for any well-defined collection of categories ${\displaystyle E}$, there exists a category ${\displaystyle \mathrm {Cat} _{E}}$ whose arrows are all functors between categories in ${\displaystyle E}$. Since no category can include itself as an object, there can be no category of all categories, but it is common and useful to designate a category small when the collection of objects is a set, and define Cat to be the category whose objects are all small categories and whose arrows are all functors on small categories.

class Functor f where