Across mathematics, many kinds of structures arise:

  • Sets and functions between them.
  • Groups and group homomorphisms between them.
  • Types and typed terms representing transformations between them.
  • Topological spaces and continuous maps between them.

What is common to all of these structures is that they consist of objects and some sort of directed relationships (arrows) between them. Adopting a birds-eye view of these structures and considering these arrows and objects as black-boxes is the starting point of category theory. Not all associations of objects and arrows (morphisms) form a category. The minimal structure of a category is:

  • Composition Exitence For all morphisms f:A→Bf : A \to B and g:B→Cg : B \to C, there exists a morphism from f∘g:A→Cf \circ g : A \to C. Note that in the bird’s-eye view of category theory, the composition of two morphisms is not defined, only that it exists and is unique. Rather, composition is defined in the close-up view of the category.
  • Associatitivity Law For all morphisms f:A→Bf : A \to B, g:B→Cg : B \to C, and h:C→Dh : C \to D, the composition is associative: (h∘g)∘f=h∘(g∘f)(h \circ g) \circ f = h \circ (g \circ f).
  • Identity Existence For all object AA in the category, there exists an identity morphism idA:A→A\mathrm{id}_A : A \to A.
  • Identity Law For all morphisms f:A→Bf : A \to B, the identity morphisms act as neutral elements for composition: idA∘f=f=f∘idB\mathrm{id}_A \circ f = f = f \circ \mathrm{id}_B.

For instance, the below is not a category, because (i) there is not identity for CC and (ii) there is no morphism that could possibly represent g∘fg \circ f:

flowchart LR
    A -->|f| B
    B -->|g| C
    A -->|id_A| A
    B -->|id_B| B
flowchart LR
    A -->|f| B
    B -->|g| C
    A -->|g o f| C
    A -->|id_A| A
    B -->|id_B| B
    C -->|id_C| C