ExpandCollapsePrev Next Index

\(\DeclareMathOperator{\obj}{obj}\ \DeclareMathOperator{\arr}{arr}\ \DeclareMathOperator{\dom}{dom}\ \DeclareMathOperator{\cod}{cod}\)

+ 3.1 Functors

A functor \(F\)is a mapping from a category \(D\) to another category \(C\) which consists of a function \(\obj F\) from objects to objects and function \(arr F\) from arrows to arrows which preserves structure in the following sense:

  1. If \(c = \obj F d\) then \(1_c = \arr 1_d\)
  2. If \(f: A \rightarrow B\) and \(g: B \rightarrow C\) then \[ \arr F (f\cdot g) = \arr F (f) \cdot \arr F (g) \]
In other words, identities and composition are preserved.

+ 3.1.1 Example: polymorphic types

A polymorphic type F, such as a C++ class template, can be considered as a functor from \(\bf Type \) to \( Type \). Given any type t, a new type F<t> is constructed.

For example then vector is a functor. Here the structure is preserved by defining \(\arr vector (f)\) the action of a \(f\) on a vector as the action on its elements. This operation is commonly called a map.

+ 3.1.2 Meta programming

We can make a category whose objects are other categories, and whose arrows are functors. So category theory has the nice property that it can describe itself.