Categories Great and Small
Bartosz Milewski ยท 2014 ยท Category Theory for Programmers, Ch. 3
Prereqs: ๐ Chapter 1 (Category). 5 min.
Orders and monoids are both categories in disguise. A preorder is a category where each hom-set has at most one morphism. A monoid is a category with exactly one object. Recognizing this collapses two chapters of abstract algebra into two sentences of category theory.
Small categories โ finite objects, finite arrows
A small category has a set (not a proper class) of objects. The simplest is the empty category: no objects, no morphisms. Next up: a single object with its identity morphism. Then categories with a handful of objects and arrows between them, as long as they close under composition and every object has an identity.
Free categories โ from graphs to categories
Start with a directed graph. Add an identity arrow at every node. Then close under composition: for every path AโBโC, add a composite arrow AโC. Keep going until no new arrows appear. The result is the free category generated by that graph. A graph with one node and one edge produces infinitely many morphisms: the edge, the edge composed with itself, and so on.
Orders โ thin categories
An ordered set is a category where the morphism aโb means "a โค b." Reflexivity gives you identity. Transitivity gives you composition. A category where every hom-set has at most one morphism is called thin. Three flavors:
- Preorder: reflexive + transitive. That's it. A thin category.
- Partial order: preorder + antisymmetric (a โค b and b โค a implies a = b). No loops.
- Total order: partial order where every pair is comparable.
Monoid as a single-object category
A monoid is a set with an associative binary operation and an identity element. String concatenation with the empty string. Addition with zero. The categorical perspective: a monoid is a category with exactly one object. The elements of the monoid become morphisms. The binary operation becomes composition. The identity element becomes the identity morphism. The hom-set M(m, m) is the monoid.
Hom-sets
The set of all morphisms from object a to object b is the hom-set C(a, b). In a thin category (preorder), every hom-set is either empty or a singleton. In a monoid-as-category, there's only one hom-set: M(m, m), and it contains every element of the monoid. A category is locally small if every hom-set is a set (not a proper class).
Notation reference
| Book | Scheme | Meaning |
|---|---|---|
| C(a, b) | (hom-set a b) | Set of morphisms from a to b |
| |C(a, b)| โค 1 | (thin-hom a b) | Thin category (preorder) |
| a โค b | (<= a b) | Morphism exists in the order-category |
| m โ n | (monoid-compose f g) | Monoid operation = composition |
| e | monoid-id | Identity element = identity morphism |
| Free(G) | (free-category-arrows ...) | Free category generated by graph G |
Neighbors
Milewski chapters
- ๐ Chapter 1 โ Category: the essence of composition
- Chapter 4 โ Kleisli categories (next)
Related pages
- ๐ Leinster 2021 โ entropy as a functor on finite probability spaces
- ๐ Spivak 2013 โ categories for the working scientist
- ๐ Judson Ch.1 Groups โ groups are one-object categories where every morphism is invertible
Foundations (Wikipedia)
Translation notes
Milewski covers the Haskell Monoid typeclass (mempty, mappend) and the distinction between point-free and pointwise equality. Here we show the same ideas in Scheme (functions and strings) and Python. The free monoid on an alphabet is the set of all strings over that alphabet with concatenation. Haskell's String type with (++) is exactly this free monoid. The categorical perspective on monoids (single-object category) is what makes them composable with everything else in category theory.