
Category Theory
Category theory is abstract, about as abstract as mathematics gets.
It is the study of systems of related objects. The relations between the objects under study are called maps (also arrows or morphisms)
Maps bind Objects together in a relationship.
Often Objects are Represented by Letters and Maps by Arrow, such as:
f g
A ---> B --> C
where we have objects A, B and C, and arrows f & g.
A and B are related through f & B and C are related through g.
Category theory born out of the studies in
Algebraic Topology was formulated precisely in the 1940’s by Samuel Eilenberg & Saunders Mac Lane.
Categories are themselves Objects.
Functors are maps between Categories.
Natural Transformations are maps between Functors.
Often the term Homomorphism is used, I like to think of it as nothing more than meaning a general morphism.
Categories
A category is just three things:
- a collection of objects ;
- for each pair of objects, a collection of arrows ;
- a way to compose arrows that line up: given and , there is .
And only two rules:
- Identity: every object has a “do nothing” arrow with and .
- Associativity: .
That is the whole definition. If it reminds you of groups, good: a group is exactly a category with one object in which every arrow can be undone.
The plain idea
Here is the truth behind the abstraction: category theory says you know a thing by its relationships, not by its insides. Set theory asks “what is this made of?” Category theory asks “how does this connect to everything else?”
It is the difference between describing a person by their DNA and describing them by who they talk to, work with and love. Both are true descriptions. The second one is often more useful.
Why it matters
Mathematics in the 20th century split into many specialised fields, each with its own objects and its own “structure-preserving maps”: functions between sets, homomorphisms between groups, linear maps between vector spaces, continuous maps between spaces. Eilenberg and Mac Lane noticed that the same arguments kept being repeated in each field. Category theory lets you make the argument once, at the level of arrows, and get every special case for free.
It has since leaked out of pure maths:
- In programming, Haskell’s
FunctorandMonadcome straight from category theory, and the idea of composing small functions into pipelines is categorical thinking. - In physics, monoidal categories give a picture language for quantum processes.
- In science more widely, “applied category theory” is used to model databases, circuits and systems that plug together.
An everyday analogy: plumbing
Think of objects as pipe fittings and arrows as lengths of pipe. You can join two pipes only if the end of the first matches the start of the second (composition needs matching ends). There is a zero-length connector that changes nothing (the identity). And if you join three pipes, it doesn’t matter which joint you tighten first (associativity). Category theory is the study of what can be built from fittings and pipes, without ever asking what the pipes are made of.
Some examples
| Category | Objects | Arrows |
|---|---|---|
| Set | sets | functions |
| Grp | groups | group homomorphisms |
| Vect | vector spaces | linear maps |
| Top | topological spaces | continuous maps |
| a preorder | elements | one arrow whenever |
The last one is a surprise: any ordering is a category. Composition is just transitivity (if and then ), and identity is reflexivity (). See Transitivity and Reflexivity: those relation properties are category axioms in disguise.
Functors
A functor is a map between categories. It sends each object to an object , and each arrow to an arrow , while respecting the structure:
A worked example: the “list” functor
Let be the category Set. Define to be the set of finite lists of elements of . Given a function , define to apply to every entry:
Check the rules with and on whole numbers:
- ✔
Mapping twice is the same as mapping the composite once. Programmers write this as map g . map f == map (g . f), and compilers use it to fuse two loops into one. That is a categorical law saving real CPU time.
Natural Transformations
A natural transformation between two functors picks, for each object , an arrow , such that for every this square commutes:
graph LR FA["F(A)"] -->|"F(f)"| FB["F(B)"] FA -->|"η_A"| GA["G(A)"] FB -->|"η_B"| GB["G(B)"] GA -->|"G(f)"| GB
Example: “reverse a list” is a natural transformation from to . Reversing and then adding one to every entry gives the same answer as adding one and then reversing. It works uniformly, without peeking at what the entries are. Mac Lane said category theory was invented precisely to define this word “natural”.
Common misconceptions
- “Category theory is just notation.” It proves real theorems. The Yoneda lemma, for instance, makes precise the slogan above: an object is completely determined by the arrows into it.
- “You need it before anything else.” No. It pays off once you already know two or three fields and want to see what they share.
- “Arrows are functions.” Often, but not always. In a preorder an arrow is just the fact ; there is nothing to “apply”.
- “It replaces set theory.” It can serve as an alternative foundation (Lawvere’s ETCS, and homotopy type theory), but most working mathematicians use both.
How it connects
- Abstraction: category theory is the top floor of the abstraction tower.
- Groups, Group Actions, Vector Spaces and Linear Operators are all categories, or objects living in them.
- Set Relations: every preorder is a small category.
- Haskell: functors and monads in everyday code.
The truth revealed: stop staring at the thing. Look at its arrows.
Further Reading
- Saunders Mac Lane, Categories for the Working Mathematician (1971, 2nd ed. 1998)
- Tom Leinster, Basic Category Theory (2014), free on arXiv
- Eugenia Cheng, The Joy of Abstraction (2022)
- Bartosz Milewski, Category Theory for Programmers
