A category is a mathematical structure for studying relationships rather than particular kinds of things. Its objects may be numbers, sets, functions, sequences, programming-language types, or even categories themselves. Its morphisms are directed relationships between objects, written A→B, and compose transitively while including reflexive relationships. Here, “object” means an object of the category, not an object in the object-oriented-programming sense. section 7.1 section 7.4
The same structure supports several useful readings:
- Treat objects as arbitrary entities and morphisms as arrows expressing relationships between them. section 7.1
- Treat programming-language types as objects and assignment compatibility as a morphism between types. section 7.4
- Use category theory to reason about composable operations, abstractions, and design patterns in programming. section 7.0
- Extend the picture with functors, which map objects between categories while preserving morphisms, either in the same or reversed direction. section 7.4
Types as a category
Imagine a category whose objects are programming-language types. Draw an arrow X→Y when an expression of type X may be assigned to a variable of type Y. These arrows represent assignment compatibility; their transitive structure lets relationships compose across several types. section 7.4
Figure 7.1 A small category with three objects, represented by the nodes, and six morphisms, represented by the arrows
A small node-and-arrow diagram makes the objects, morphisms, and directional structure visible before introducing more elaborate categorical constructions. section 7.1
