Category Theory
Category Theory is about how objects are related to each other. A category is a collection of objects and arrows, also known as morphisms, between those objects. 1
Notably, Category Theory is more focused on morphisms rather than what the objects are exactly. 2 When applied to programming, the advantages given by category theory allow you to compose things together more easily. These advantages are lost if you have to dig into the implementation of an object in order to understand how to compose it with other objects. 1
Types of categories:
Reading material:
- Category Theory Illustrated by Jencel Panic 2
- Category Theory for Programmers by Bartosz Milewski 3
- The Joy of Abstraction by Eugenia Cheng 2
- Category Theory in Context by Emily Riehl 2
- Category Theory for the Working Mathematician by Saunders Mac Lane 1
Category
- A collection of objects and morphisms that go from one object to another.
- There is a way to compose two morphisms into a third one which gives the result of applying the morphisms successively in an associative way.
- Each object has to have the identity morphism.
The identity morphism is useful, because it can be used as an argument to or a return from a higher-order function. Higher-order functions make the symbolic manipulation of functions possible. 1
Dual
An example of dual categories can be seen in the product and sum operations from Set Theory. In each of the product and sum operations, you can consider "imposter" sums and "imposter" products which contain additional information which can be removed with a morphism. 2
Specifically, you can always create a new
imposter sum with a trivial function that goes from
A + B -> A + B + X and you can
always create a new imposter product that goes from
A x B x X -> A x B. You can see by
looking at the formulas how the extra information
X is on different sides of the
function. 2
Anything that has this kind of relationship is said to be dual to one another. The concepts of product and sum are dual and it's why sums are known as converse product or coproduct. 2