These are my lecture notes on Bartosz Milewski's course on category theory. These are not meant as a comprehensive guide but rather a loose collection of definitions and short summaries.

## General stuff

A category is a collection of objects along with arrows, called morphisms, between those objects. It is therefore similar to a labeled directed graph.
A category has two properties: composition of morphisms and identity. Composition in category theory is similar to composition of functions and behaves associatively. Identity means that every object has an identity morphism. Morphisms between any two objects form a set called the hom set denoted as $$hom(a, b)$$. In higher-order categories morphisms don't form sets, they form objects in a category. A groupoid is a category in which every morphism has an inverse. A category whose objects form a set is called small, otherwise it's called large. An algebraic group is a category with a single object (corresponding to the set of elements of the group). A morphism $$f: a \rightarrow b$$ is called
• an epimorphism (or epic) if it is right-cancellable, i.e. $$g_1 \circ f = g_2 \circ f$$ implies $$g_1 = g_2$$ for all $$c$$ and all $$g_1, g_2: b \rightarrow c$$
• a monomorphism (or monic) if it is left-cancellable, i.e. $$f \circ g_1 = f \circ g_2$$ implies $$g_1 = g_2$$ for all $$c$$ and all $$g_1, g_2: c \rightarrow a$$
• a bimorphism if it is both a monomorphism and an epimorphism
• An isomorphism if it has an inverse, i.e. if there exists an morphism $$f^{-1}: b \rightarrow a$$ with $$f^{-1} \circ f = id_a$$ and $$f \circ f^{-1} = id_b$$.

## Set

Set (capitalized) is the category of sets and functions. Set is a category because there is an identity function for each set which becomes the identity morphism in Set and function composition (which becomes morphism composition in Set) is associative.

In Set: surjective functions correspond to epimorphisms, injective functions correspond to monomorphisms and bijective functions correspond to bimorphisms.
Also notice the distinction between isomorphisms and bimorphisms. While in set theory a function that is bijective (both injective and surjective) is invertible, in category theory a bimorphism (which is both epic and monic) is not necessarily invertible (an isomorphism).

## Category Theory in Programming

In a general sense, types in programming languages are sets:

• Boolean represents the set $$\{True, False\}$$
• Int represents a subset of $$\mathbb{N}$$
• Float/Double represents a subset of $$\mathbb{Q}$$
If we go in the other direction we can ask which type in programming a specific set corresponds to:

### The Empty Set

The empty set does not correspond to any type in most imperative languages, it does however correspond to the type Void in Haskell (omitting the bottom element).

We can define the following (uncallable) functions with Void in Haskell:
absurd :: Void → a
id_void :: Void → Void


### The Singleton Set

The (one element) singleton set has one element called () and we can build the unit function with it:
unit :: a → ()

Furthermore we can define infinitely many functions of type () → a. These individual functions are constant. In this way we can express elements of a set as functions, or in category theory as morphisms.
For example for type bool we can define the functions
true :: () → Bool
true _ = True
false :: () → Bool
false _ = False

Here we have expressed the elements of the type set of Bool as morphisms.
Such an object () that allows us to view individual elements of a set as morphisms does not exist for every category. In general, category theory abstracts over elements and looks at sets, functions and other things from a higher perspective.

### The two-element Set

(todo)

Sidenote: There is an important difference between pure functions in programming and mathematical functions. Mathematical functions instantly evaluate to a certain result while functions in programming may not terminate. To avoid this issue a special element called bottom is added to all type-sets above and a non-terminating function is said to return this bottom value.