0% found this document useful (0 votes)
26 views76 pages

Category Theory For Programming

This document provides lecture notes on introducing category theory concepts with applications to functional programming. It begins with an introduction explaining the purpose and structure of the notes. The main topics covered include initial algebras, which provide a mathematical characterization of datatypes and recursion, and monads, which provide a framework for modeling effects in functional languages. The notes include examples and exercises throughout.

Uploaded by

Alberto Cendrós
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views76 pages

Category Theory For Programming

This document provides lecture notes on introducing category theory concepts with applications to functional programming. It begins with an introduction explaining the purpose and structure of the notes. The main topics covered include initial algebras, which provide a mathematical characterization of datatypes and recursion, and monads, which provide a framework for modeling effects in functional languages. The notes include examples and exercises throughout.

Uploaded by

Alberto Cendrós
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

Category Theory for Programming

Benedikt Ahrens Kobe Wullaert


arXiv:2209.01259v1 [cs.PL] 2 Sep 2022

We thank Arnoud van der Leer for their contributions to these notes.

This work is licensed under a Creative Commons “Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)”
license. cba
The source code for this document can be obtained from
https://github.com/benediktahrens/CT4P.

1
Abstract In these lecture notes, we give a brief introduction to some elements of cate-
gory theory. The choice of topics is guided by applications to functional programming.
Firstly, we study initial algebras, which provide a mathematical characterization of
datatypes and recursive functions on them. Secondly, we study monads, which give a
mathematical framework for effects in functional languages. The notes include many
problems and solutions.

2
Contents
1. Introduction 4
1.1. About These Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2. About Category Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3. Learning Material on Category Theory . . . . . . . . . . . . . . . . . . . 4
1.4. Notations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

2. Categories 5
2.1. Isomorphisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.2. Sections and Retractions . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.3. Monomorphisms and Epimorphisms . . . . . . . . . . . . . . . . . . . . 16

3. Universal Properties 18
3.1. Initial Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.2. Terminal Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.3. (Binary) Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.4. (Binary) Coproducts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

4. Functors 22
4.1. Categories as objects of a category? . . . . . . . . . . . . . . . . . . . . 24

5. Natural transformations 26
5.1. Functor categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
5.2. Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
5.3. Equivalence of categories . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

6. Adjunctions 30

7. Monads and Effects 33

8. Inductive Datatypes and Initial Algebras 36


8.1. Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
8.2. Datatypes as Initial Algebras . . . . . . . . . . . . . . . . . . . . . . . . 37

9. Fusion Property 43

10.Terminal Coalgebras and Coinductive Datatypes 44

11.Solutions 46

A. Forgetful and free functors 71


A.1. Contravariant functors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

3
1. Introduction
Category theory is a framework which allows one to formally describe and relate math-
ematical structures. By a mathematical structure, we mean, informally, a collection
of things (like types, sets, etc.) and something which transforms one thing to another
thing (like a program, function, etc.).
This framework started as a mathematical theory, but has now proven itself useful
also in the world of Computer Science (and beyond). In this course we will intro-
duce the necessary concepts from category theory with the goal of understanding its
applications in the realm of programming.

1.1. About These Notes


These notes are not meant to give an exhaustive introduction to category theory. In-
stead, the aim is to develop just as much category theory as is necessary to discuss some
interesting applications of category theory to computing, specifically, to programming.
Throughout these notes, pointers to other sources, such as textbooks and research
articles, are given; it is highly recommended to consult these sources.

1.2. About Category Theory


Category theory is a mathematical area of endeavour and language developed to rec-
oncile and unify mathematical phenomena from different disciplines. It was developed
from the 1940s on, in particular by Samuel Eilenberg and Saunders Mac Lane.
Computer science is. . . well, you know what it is.
In this course, we learn about some fundamental applications of category theory to
computer science, specifically, to programming. The power of category theory arises
from abstraction: by boiling down constructions to their essence, analogous situa-
tions can be formally identified using category theory. One crucial concept provided
by category theory to this end is that of universal property; we study some univer-
sal properties in Section 3. An application of universal properties to the theory of
datatypes and structural recursion is studied in Section 8.
Another categorical concept that has proved particularly useful in programming is
that of a monad. We study monads and their use in programming in Section 7.

1.3. Learning Material on Category Theory


The scientific literature on category theory in computer science is vast. We list some
learning material on category theory.
Pierce’s book [9] (available for free) gives a brief introduction to category theory
with some applications to computing.
Leinster’s book [7] (available for free online, under a free license) gives a concise
introduction to category theory. It is a good resource for the basic concepts, but does
not feature many examples from computer science.

4
The rather substantial textbook by Barr and Wells [1] (available for free online)
covers a lot more than we are going to discuss in these notes.
The Catsters [2] provide a lecture series on category theory on YouTube.

1.4. Notations
A list of notations which we use throughout these lectures notes.
• If X is a set and x is an element of X, we write x ∈ X.
• If X is a set and P and Q are properties dependent over the elements of X, we
write P =⇒ Q to express that if P (x) holds for an element x ∈ X, then also
Q(x) should hold for the element x. Moreover, we write P ⇐⇒ Q if P =⇒ Q
and Q =⇒ P .
• If X is a set and P is a property dependent over the elements of X, we write:
(*) ∀x ∈ X : P (x) to express that for every element in X, the property P holds.
(*) ∃x ∈ X : P (x) to express that there exists at least one element in X for
which the property holds.
(*) ∃!x ∈ X : P (x) to express that there exists a unique element in X for which
the property holds.
• Let X and Y be sets. We denote:
(*) X × Y for the (cartesian) product of X and Y .
(*) X ⊔ Y for the disjoint union of X and Y .

2. Categories
Further Reading. The definition of categories is also given in [1, §2.1]. Plenty of
examples of categories are given in [1, §§2.3–2.5].
The definition of categories is also given in [7, §1.1], together with some examples.
There, also isomorphisms are discussed, which we define in Section 2.1.
The tutorial [9] features the definition of categories in [9, §2.1]. It also introduces
the notion of “diagram”, which we do not use in the present notes.
Definition 1. A category C consists of the following data:
1. A collection of objects, denoted by C0 .
2. For any given objects X, Y ∈ C0 , a collection of morphisms from X to Y , denoted
by homC (X, Y ) (or hom(X, Y ) when the category C is clear, or C(X, Y ) or X →
Y ) and which is called a hom-set.
3. For each object X ∈ C0 , a morphism IdX ∈ homC (X, X), called the identity
morphism on X.

5
4. A binary operation

(◦)X,Y,Z : hom(Y, Z) → hom(X, Y ) → hom(X, Z),

called the composition operator, and written infix without the indices X, Y, Z as
in g ◦ f .
Moreover, this data should satisfy the following properties:
1. (Left unit law) For any morphism f ∈ hom(X, Y ), we have

f ◦ IdX = f.

2. (Right unit law) For any morphism f ∈ hom(X, Y ), we have

IdY ◦ f = f.

3. (Associative law) For any morphisms f ∈ hom(X, Y ), g ∈ hom(Y, Z) and


h ∈ hom(Z, W ), we have

h ◦ (g ◦ f ) = (h ◦ g) ◦ f.

Intuition 2. So what does a category represent? There are (at least) 3 possible ways
how one can think about this definition:
1. A category represents a type system in the sense that the objects are the types
and each hom-set is the type1 of functions. See Definition 10.
2. A category represents a bag of instances of a particular mathematical structure
(e.g. sets with a notion of addition). The objects are then instances of such a
mathematical theory (e.g. (N, +)) and the morphisms are structure preserving
functions (e.g. functions f which satisfy f (x+y) = f (x)+f (y)). See Examples 4
and 14 and Definition 19.
3. A category represents a directed graph in the sense that an object is a vertex
and a morphism is an edge.
4. Anything (almost at least) can be seen as a category in some exotic way.
Notation 3. Let C be a category.
• We write X ∈ C instead of X ∈ C0 .
• Let X, Y ∈ C be objects. A morphism f ∈ C(X, Y ) can be visualized as
f
X−
→ Y.
1 Inthis case, each hom-set is a type, so isn’t each hom-set an object again? Categories which satisfy
such a property are called cartesian closed.

6
• Let X, Y, Z ∈ C0 objects in C and consider the following morphisms:

f ∈ C(X, Y ), g ∈ C(Y, Z), h ∈ C(X, Z).

These morphisms can be visualized as a triangle:


f
X Y
g
h
Z

We say that such a triangle commutes if h = g ◦ f .


• Let X, Y1 , Y2 , Z ∈ C0 objects in C and consider the following morphisms:

f1 ∈ C(X, Y1 ), f2 ∈ C(X, Y2 ), g1 ∈ C(Y1 , Z), g2 ∈ C(Y2 , Z).

These morphisms can be visualized as a square:


f2
X Y2
f1 g2

Y1 g1 Z

We say that such a square commutes if g1 ◦ f1 = g2 ◦ f2 .


Example 4. The Category of sets, denoted by Set, is the category specified by the
following data:
• An object is a set.
• If X and Y are sets, then is Set(X, Y ) the set of all functions from X to Y .
• The identity morphism IdX (on X ∈ Set0 ) is the identity function on X, i.e.

IdX : X → X : x 7→ x.

• The composition of functions is given by the usual composition of functions, i.e.


for f ∈ Set(X, Y ) and g ∈ Set(Y, Z), the composition of f and g is:

g ◦ f : X → Z : x 7→ g(f (x)).

Lemma 5. The data of Set satisfies the properties of a category, hence Set is indeed
a category.
Proof. We first show that the left unit law holds. Let X, Y ∈ Set be sets and f ∈
Set(X, Y ) a function. We have to show that IdX · f = f , hence it suffices to show that
they pointwise equal which holds by the following calculation:

∀x ∈ X : (f ◦ IdX )(x) = f (IdX (x)) = f (x),

7
where the first (resp. second) equality holds by definition of the composition (resp.
identity morphism).
That the right unit law holds is analogous. To show that the associator law holds, let
X, Y, Z, W ∈ Set and f ∈ Set(X, Y ), g ∈ Set(Y, Z) and h ∈ Set(Z, W ). We have to
show h ◦ (g ◦ f ) = (h ◦ g) ◦ f , hence it suffices again to show that they are pointwise
equal which holds by the following calculation:
∀x ∈ X : (h ◦ (g ◦ f )) (x) = h ((g ◦ f )(x)) ,
= h(g(f (x))),
= (h ◦ g)(f (x)),
= ((h ◦ g) ◦ f ) (x),
where the first (resp. second, third, fourth) equality holds by definition of the compo-
sition of h and g ◦f (resp. composition of g and f , composition of h and g, composition
of h ◦ g and f ).
We are now going to describe the category whose collection of objects is given by
collection of Lean types:
Example 6. Consider the following data:
• An object is a Lean type (of some fixed universe).
• If X and Y are Lean types, then is LEAN(X, Y ) the function type X → Y .
• The identity morphism IdX (on X ∈ LEAN0 ) is the identity function on X, i.e.
d e f i d f u n (X : Type ) : X → X := λ x , x .

• The composition of functions is given by the composition of functions:


d e f compfun {X Y Z} ( f : X → Y) ( g : Y → Z ) : X → Z
:= λ x , g ( f x )

Try it out, e.g., on https://leanprover.github.io/live/latest/:


#e v a l compfun (+1) ( ˆ 3 ) 5
(You can get a pre-filled Lean input field by clicking here: ClickMe.)
Exercise 7. Prove (on paper) that the data defined in Example 6 defines a category.
That is, show that it satisfies the axioms of a category. You might need to use the
axiom of functional extensionality:
axiom f u n e x t n o n d e p : ∀ {A B : Type } ( f g : A → B ) ,
(∀ x , f x = g x ) → f = g

Example 8. We repeat the definitions of Example 6 in Haskell instead of Lean. Does


this data satisfies the axioms of a category?
Due to Haskell allowing for the undefined value in each type, the situation is slighly
more complicated; consider the following two functions:

8
u n d e f 1 : : a −> a
undef1 = u n d efin ed

u n d e f 2 : : a −> a
u n d e f 2 = \ x −> u n d e f i n e d
These are not equal by definition, but we have Id· undef1 = undef2. So by the right
unit law, we must have that undef1 = undef2 (as morphisms in our sought category).
Exercise 9. Read the Haskell wiki page on the category Hask [4].
However, when considering functions to equal when they are pointwise equal, we
can define a category of Haskell types:
Definition 10. The category of Haskell types, denoted by Hask, is the category
specified by the following data:
• An object is a Haskell type.
• If X and Y are Haskell types, then is Hask(X, Y ) the collection of functions
modulo the equivalence relation ∼ defined by identifying pointwise equal func-
tions:
f ∼ g : ⇐⇒ ∀x : X, f (x) = g(x).
i.e. a morphism in Hask is an equivalence class of (Haskell) functions.
• The identity morphism IdX (on X ∈ Hask) is the equivalence class of the identity
function on X.
• The composition of (Haskell) functions is given by the equivalence class of the
composition of functions, i.e., for f ∈ Hask(X, Y ) and g ∈ Hask(Y, Z), the
composition of f and g is the equivalence class of:

g ◦ f : X → Z : λx.g(f (x)).

Example 11. Recall that a preordered set (X, ≤) consists of a set X together with a
binary relation (≤) on X which satisfies the following properties:
• Reflexivity: ∀x ∈ X : x ≤ x.
• Transitivity: ∀x, y, z ∈ X : (x ≤ y ∧ y ≤ z) =⇒ x ≤ z.
Let (X, ≤) be a preordered set. The following data induces a category Pre(X, ≤):
• The objects are the elements of X.
• Let x, y ∈ X be elements. The hom-set hom(x, y) consists of a unique element
if x ≤ y and is empty otherwise.
• We need an identity morphism for each x ∈ X. By reflexitivity (i.e., x ≤ x),
we have that hom(x, x) consists of a unique element, which we take to be the
identity.

9
• We need to define for each x, y, z ∈ X, a composition operator:

hom(y, z) → hom(x, y) → hom(x, z).

By definition of the hom-sets, we only have to define it in case x ≤ y and y ≤ z.


But then, by transitivity (i.e. if x ≤ y and y ≤ z, then x ≤ z), we have that
hom(x, z) consists of a unique element which we take to be the composition.
We are now going to show that the axioms of a category holds. To show the right unit
law, we have to show that for each x, y ∈ X and f ∈ hom(x, y), we have f ◦ Idx = f .
This indeed holds since every hom-set has a unique element, but both f ◦ Idx and f
live in the same hom-set, hence they must be equal. The proof that left unit law and
associator law hold are analogous.
Exercise 12 (Solution 210). A partially ordered set (poset) is a preordered set
(X, ≤) satisfying the following additional axiom:
• Antisymmetry: ∀x, y ∈ X : (x ≤ y ∧ y ≤ x) =⇒ x = y.
What does this axiom say about Pre(X, ≤)?
Remark 13. To understand a definition in category theory, it is very helpful to think
about what the definition means in a preordered set, viewed as a category.
Example 14. The category of posets, denoted by Pos, is the category specified by
the following data:
• An object is a poset (X, ≤).
• A morphism from a poset (X, ≤X ) to (Y, ≤Y ) consists of a function f : X → Y
such that the following property holds:

∀x1 , x2 ∈ X : x1 ≤X x2 =⇒ f (x1 ) ≤Y f (x2 ).

• The identity morphism on (X, ≤X ) is the identity function on X.


• The composition given by the composition of functions.
Before we can show that this data satisfies the axioms of a category, notice that the
identity function is a morphism of posets and that the composition of poset morphisms
is again a poset morphism, indeed: If x1 ≤X x2 , then we also have IdX (x1 ) ≤X IdX (x2 )
because IdX (x) = x. If f ∈ Pos((X, ≤X ), (Y, ≤Y )) and g ∈ Pos((Y, ≤Y ), (Z, ≤Z )) are
morphisms of posets, then we have

∀x1 , x2 ∈ X : x1 ≤X x2 =⇒ f (x1 ) ≤Y f (x2 ) =⇒ g(f (x1 )) ≤Z g(f (x2 )),

where the first (resp. second) inequality holds by f (resp. g) being a morphism of
posets. So our data is indeed well-defined.
That the axioms of a category are satisfied by this data, is exactly the same proof as
showing that Set is a category because the identity and composition are defined in
the same way.

10
Exercise 15 (Solution 211). Is Pos a preorder-category itself? That is, is there at
most one morphism between any two objects?
Question 16. In Example 14, we have shown that Pos is a category. However, by
Example 11, we know that any poset also is a category. So we have that Pos is a
category whose objects are certain categories. Can we also have some category whose
collection of objects is the collection of all categories, and if so, what are the morphisms
of categories?
Solution. Section 4 is devoted completely to this answer.
Lemma 17. Let C be a category. For any object X ∈ C, IdX is the unique morphism
which satisfies the following property: For any Y ∈ C and f ∈ C(X, Y ), we have

f ◦ IdX = f.

Proof. Assume Id˜X also satisfies this property, in particular we have IdX ◦ Id˜X = IdX .
However, by the right unit law, we also must have IdX ◦ Id˜X = Id˜X . Hence, IdX =
Id˜X .
Example 18. In this example we are going to associate a category which captures the
multiplication of the rational numbers. Let C be the category defined by the following
data:
• There is a unique object ⋆.
• The (only) hom-set is given by

hom(⋆, ⋆) = Q,

i.e. each morphism corresponds with a rational number.


• The composition is defined by the multiplication of rational numbers:

Q → Q → Q : (p, q) 7→ p · q.

• The identity morphism (of ⋆) is given by 1.


That C is indeed a category follows because for each p ∈ Q, we have p · 1 = p = 1 · p
(which shows the unit laws) and by associativity of multiplication, i.e. (p·q)·h = p·(h·q)
(which shows the associativity of the composition).
The construction in Example 18 uses no specific properties of the rational numbers,
only that it has a multiplication which is associative and such that there is a special
element which does not change an element when it is multiplied with this special
element. Hence, Example 18 can be generalized as follows:

11
Definition 19. Recall that a monoid is a set M equipped with binary operation
m : M → M → M which is associative, i.e.

∀x, y, z ∈ M : m(x, m(y, z)) = m(m(x, y), z),

and such that there is an identity element, i.e.

∃e ∈ M : ∀x ∈ M : m(e, x) = x = m(x, e).

Let (M, m, e) be a monoid. The category Monoid(M, m, e) is defined by the following


data:
• There is a unique object ⋆.
• The (only) hom-set is given by

hom(⋆, ⋆) = M.

• The identity morphism on ⋆ is the identity element e.


• The composition of morphisms x and y is given by y ◦ x := m(x, y).
That for each monoid (M, m, e), Monoid(M, m, e) is indeed a category, follows
directly by the properties of being a monoid. Indeed, the axioms of a category become
precisely:
1. ∀x ∈ M : m(x, e) = x,
2. ∀x ∈ M : m(e, x) = x,
3. ∀x, y, z ∈ M : m(m(x, y), z) = m(x, m(y, z)).
Remark 20. Notice that this category illustrates that there is no relation between
the collection of objects and the hom-sets since there is now only one object and the
collection of the hom-set can be as small or as large as possible.
In fact, we can associate a different number of categories to a single monoid. We can
for example consider an arbitrary set of objects I and the defining the hom-sets as
follows: (
M, if i = j,
hom(i, j) :=
∅, if i 6= j.

Exercise 21 (Solution 212). Let C be a category. When is C of the form Monoid(M, m, e),
i.e. does there exists a monoid (M, m, e) such that C = Monoid(M, m, e)?
Exercise 22 (Solution 213). Define a category Monoid whose objects are monoids,
i.e. define a suitable notion of morphism between monoids and moreover show that
this indeed defines a category.
Exercise 23 (Solution 214). Define a category C whose objects are the natural num-
bers (i.e. C0 = N) and whose hom-sets C(n, m) are given by the (n × m)-matrices.

12
Exercise 24 (Solution 215). Let C be a category. Define a category C op such that
• the objects of C op are the same as those of C; and
• the morphisms C op (X, Y ) are morphisms C(Y, X).
The category C op is called the opposite (category) of C.
Exercise 25. Let G be a directed graph. Then G induces a category Graph(G) as
follows:
• The collection of objects Graph(G)0 is the set of vertices of G.
• The morphisms between object are the (directed) paths, that is, finite sequences
of composible edges, between them.
• For each object x (i.e. vertex), the identity morphism on x is the identity path.
• The composition of morphisms is the composition of paths.
We call Graph(G) the category generated by G. Show that Graph(G) is indeed
a category.
Exercise 26. Argue why the morphisms are chosen to be paths and it is not sufficient
to just take the vertices.
Example 27. Consider the following graph G:
x
i.e. the graph with only object vertex and no edges. The category generated by G is
the category generated is the so-called terminal category, that is, the category with a
single object and a single morphism (the identity morphism of the unique object).
Example 28. Consider the following graph G:
x y

The category generated by G is the category generated is the so-called interval category,
that is, the category with two objects and, besides the identity morphisms, a unique
morphism (living in hom(x, y)).
In the following example we use the following notation:
• If f is a morphism in a category, we denote f 2 := f ◦ f, f 3 := f 2 ◦ f , etc.
• We also label the edges in order to refer to them.
Example 29. Consider the following graph G:
f
x y
g

The category generated by G consists of the following data:

13
• The collection of objects is {x, y}.
• The hom-sets are given as follows:
– hom(x, x) contains

Idx , g ◦ f, (g ◦ f )2 , (g ◦ f )3 , · · · ,

But these are not the only ones, we also have that each of these can be
precomposed or postcomposed with Idx , however, by the unit laws, we know
that these don’t give us any new morphisms. The same remark holds for
the associativity law. This comment also holds for the upcoming hom-sets.
– hom(y, y) contains

Idy , f ◦ g, (f ◦ g)2 , (f ◦ g)3 , · · · ,

– hom(x, y) contains

f, (f ◦ g) ◦ f, (f ◦ g)2 ◦ f, (f ◦ g)3 ◦ f, · · ·

– hom(y, x) contains

g, (g ◦ f ) ◦ g, (g ◦ f )2 ◦ g, (g ◦ f )3 ◦ g, · · ·

Example 30. Consider the following graph G:


w

x z

The category generated by G has four objects (namely x, y, z, w) and the hom-sets are:
• hom(y, x), hom(y, z) and hom(z, w) are singleton sets,
• hom(x, y), hom(z, y), hom(x, w), hom(w, x) and hom(w, z) are all empty.
• hom(y, w) consists of the path y → z → w.
• For each vertex v, we have that hom(v, v) consists only of the identity path on
v.
Exercise 31 (Solution 216). Describe the connection between the categories generated
by graphs and the categories associated to preordered sets. What is the property of
anti-symmetry translated under this connection with graphs?
Exercise 32. Define a category Aut whose objects are (deterministic finite) au-
tomata.

14
2.1. Isomorphisms
Further Reading. In this section, we study properties of arrows in a category. More
information on this topic is given in [1, §2.7].
Also, [9, §2.2] briefly discusses isomorphisms.
Definition 33 (Isomorphism). Given a category C, objects a, b ∈ C0 and a morphism
f : a → b in C, we say that f is an isomorphism when there is a morphism g : b → a
(in the other direction!) such that f · g = Id and g · f = Id. We write f : a ∼ = b for a
morphism f that is an isomorphism.
In this case, we call g the inverse of f and f the inverse of g. (The latter is justified
by Exercise 34.)
Exercise 34 (Solution 217). Show that if f : a → b is an isomorphism with inverse
g : b → a, then g is an isomorphism with inverse f .
Exercise 35 (Solution 218). Show that a morphism f : a → b in C is an isomorphism
in at most one way, that is, show that its inverse is unique if it exists.
Exercise 36 (Solution 219). Show that the composition of two isomorphisms is an
isomorphism.
Remark 37. Since any identity morphism is an isomorphism (check this!), we con-
clude by Exercise 36 that given any category C, we always get a new category isos(C)
by restricting the morphisms to be isomorphisms, i.e.
isos(C)0 = C0 , isos(C)(X, Y ) = {f ∈ C(X, Y ) | f is an isomorphism}
and where the identity and composition is the same as in C.
Exercise 38 (Solution 220). Consider the Haskell datatype
d a t a BW = B l a c k | White
Construct two (different!) isomorphisms between BW and the type Bool of booleans.
Exercise 39 (Solution 221). Characterize the isomorphisms in Set.
Exercise 40 (Solution 222). Describe the isomorphisms in Pos.
Exercise 41 (Solution 223). Let (X, ≤) be a poset. Can you characterize the isomor-
phisms in Pos(X, ≤)?
Exercise 42. Can you characterize the isomorphisms in Monoid?
Exercise 43. Let G be the category generated by the following graph:
w

x z

y
Show that the only isomorphisms in G are the identity morphisms (i.e. the identity
paths).

15
2.2. Sections and Retractions
Definition 44 (Section, Retraction). A pair (s, r) of morphisms s : a → b and r : b →
a in C is called a section-retraction pair if r ◦ s = Idb .
In such a case, we call s a section and r a retraction.

Remark 45. Note that a morphism can be a retraction in more than one way, that
is, there can be more than one section s such that r ◦ s = Id.
Intuitively, a section-retraction pair (s, r) of morphisms s : a → b and r : b → a in a
category C provides a way for a to “live inside” b. Note that for a given a and b there
can be many ways for a to live inside b.
Exercise 46 (Solution 224). Construct two different section-retraction pairs between
the type Bool of booleans and the type Int of integers (e.g., in Haskell).
Exercise 47. Show that the type Maybe a is a retract of the type [a] .
Hint: The idea is that Nothing corresponds to the empty list [] and that Just x
corresponds to the one-element list [x] . Make this idea precise by writing back and
forth functions between these types so that they exhibit Maybe a as a retract of [a] .

2.3. Monomorphisms and Epimorphisms


Further Reading. See also [7, p. 134] and [1, §§2.8–2.9]. Also, [9, §2.2] briefly
discusses monomorphisms and epimorphisms.
From undergraduate mathematics courses you know what injective and surjective
functions between sets are. The definitions of “injective” and “surjective” do not carry
over to any category (though they do for categories that are, in some sense, “similar”
to the category of sets). In this section, we study two properties of morphisms in a
category that, in the category of sets, are equivalent to “injective” and “surjective”,
respectively.

Definition 48 (Monomorphism). Let f : a → b be a morphism in C. We say that f


is a monomorphism if, for any two morphisms g1 , g2 : z → a, like in the following
diagram,
g1 f
z a b
g2

we have
f ◦ g1 = f ◦ g2 implies g1 = g2 .
Exercise 49 (Solution 225). In the category of sets, show that a morphism f : X → Y
is a monomorphism if and only if it is injective.
Definition 50 (Epi). Let f : a → b be a morphism in C. We say that f is an
epimorphism if, for any two morphisms g1 , g2 : b → z, like in the following diagram,

16
f g1
a b z
g2

we have
g1 ◦ f = g2 ◦ f implies g1 = g2 .

Exercise 51. In the category of sets, show that a morphism f : X → Y is an


epimorphism if and only if it is surjective.
Exercise 52 (Solution 226). In the category of sets, show that if (s, r) is a section-
retraction pair, then is the section s injective. Hint: you can use Exercise 49.
Exercise 53. In the category of sets, show that if (s, r) is a section-retraction pair,
then the retraction r is surjective. Hint: you can use Exercise 51.

Exercise 54 (Solution 227). Show that any isomorphism f : a ∼


= b (in some arbitrary
category C) is both a monomorphism and an epimorphism.
Exercise 55 (Solution 228). Show that the converse of Exercise 54 does not hold in
general, i.e. give an example of a category where there exists a morphism which is
both an epi- and a monomorphism, but which is not an isomorphism.
Hint: Consider a preordered set.
Exercise 56. Let G1 (resp. G2 and G3 ) be the category generated by the following
graph:
w

x z

y
resp.
w

x z

y
resp.
w

x z

y
Can you characterize the mono- and epimorphisms in these categories?

17
Exercise 57. Can you characterize the monomorphisms, epimorphisms and isomor-
phisms in the category generated by the following graph:

x y

3. Universal Properties
In this section, we discuss special objects in a category.
Further Reading. On initial and terminal objects, see also [1, §2.7.16] and [7, p.
48ff].
Products and coproducts, other special limits and colimits, and the general definition
of limits and colimits, are discussed in [7, §§5.1, 5.2].
Pierce’s tutorial discusses the (co)limits defined here in [9, §§2.3–2.4], and further
(co)limits in [9, §§2.5–2.7].

3.1. Initial Objects


Definition 58. Let C be a category. An object A ∈ C0 is initial if there is exactly
one morphism from A to any object B ∈ C0 .
Exercise 59. Does the category • have an initial object?
Exercise 60. Does the category

A B

have an initial object?


Exercise 61. Does the category A → B have an initial object?
Exercise 62. Does the category A ⇄ B have an initial object? (Here, the morphism
A → B is inverse to the morphism B → A.)
Exercise 63. Does the category A ⇒ B have an initial object?
Exercise 64. Does the category
f

A B

have an initial object? (Here, the morphism f is different from IdA ).


Exercise 65 (Solution 229). Identify an initial object in the category Set of sets.
Prove that it is indeed initial.
Exercise 66. Identify an initial object in the category LEAN of Lean types. Prove
that it is indeed initial.

18
Exercise 67 (Solution 230). Let (X, ≤) be a poset. Describe what an initial object
looks like in Pos(X, ≤).
Exercise 68 (Solution 231). Let A and A′ be initial objects in C. Construct an
isomorphism i : A ∼
= A′ .
Exercise 69 (Solution 232). Let A be an initial object in C, and let A′ be isomorphic
to A (via an isomorphism i : A ∼
= A′ ). Show that A′ is an initial object of C.
Remark 70. Exercises 68 shows that initial objects in a category C are essentially
unique, that is, they are unique up to (unique) isomorphism.
This justifies using the determinate article: we will say that A is the initial object
of C.
This is more generally the case for any object with a universal property, see, e.g.,
Exercises 82 and 94.
Exercise 71 (Solution 233). Construct a category that does not have an initial object.
Exercise 72 (Solution 240). Let PtSet be the category of pointed sets, that is the
category whose objects are pairs (X, x) with X a set and x ∈ X and a morphism from
(X, x) to (Y, y) is defined as a function f : X → Y such that f (x) = y. Identify an
initial object in PtSet.
Remark 73. The concept of initial object seems trivial and boring in the categories
considered above. However, in complicated categories, initial objects can be compli-
cated and exciting; we will see this in Section 8.

3.2. Terminal Objects


Definition 74. Let C be a category. An object B ∈ C0 is terminal (or final) if there
is exactly one morphism to B from any object A ∈ C0 .
Exercise 75. Does the category • have a terminal object?
Exercise 76. Does the category A → B have a terminal object?
Exercise 77. Does the category A ⇄ B have a terminal object?
Exercise 78. Does the category A ⇒ B have a terminal object?
Exercise 79 (Solution 241). Identify a terminal object in the category Set of sets.
Prove that it is indeed terminal.
Exercise 80. Identify a terminal object in the category LEAN of Lean types. Prove
that it is indeed terminal.
Exercise 81 (Solution 242). Let (X, ≤) be a poset. Describe what a terminal object
looks like in Pos(X, ≤).
Exercise 82 (Solution 243). Let B and B ′ be terminal objects in C. Construct an
isomorphism i : B ∼
= B′.

19
Exercise 83 (Solution 244). Let B be a terminal object in C, and let B ′ be isomorphic
to B (via an isomorphism i : B ∼
= B ′ ). Show that B ′ is a terminal object of C.
Exercise 84 (Solution 245). Show that C has a terminal object if and only if C op has
an initial object.
Exercise 85 (Solution 246). Construct a category that does not have an terminal
object.

3.3. (Binary) Products


Definition 86. Let C be a category and let A, B ∈ C0 be objects of C.
A triple (P, πl : P → A, πr : P → B) is called a product of A and B if for any
triple (Q, q1 : Q → A, q2 : Q → B) there is exactly one morphism f : Q → P such that
the following diagram commutes:

Q
q1 q2
f

A πl P πr B

If A and B have a specified product (P, πl : P → A, πr : P → B), then the object P is


often called A × B. The morphism f : Q → A × B determined by (Q, q1 , q2 ) is denoted
by hq1 , q2 i.

Exercise 87. Does the category • have products?


Exercise 88. Does the category A → B have products?
Exercise 89. Does the category A ⇄ B have products?
Exercise 90. Does the category A ⇒ B have products?
Exercise 91 (Solution 247). Identify a product of sets X and Y in the category Set
of sets. Prove that it is indeed a product.
Exercise 92. Identify a product of types A and B in the category LEAN of Lean
types. Prove that it is indeed a product.
Exercise 93 (Solution 248). Let (X, ≤) be a poset. Describe what a product looks
like in Pos(X, ≤).
Exercise 94 (Solution 250). Given two products of A and B in a category C, construct
an isomorphism between them, that is, between their underlying objects.
Exercise 95 (Solution 251). Given a product (P, πl : P → A, πr : P → B) of A and
B in C, and an object P ′ that is isomorphic to P via an isomorphism i : P ∼
= P ′,

construct a product with object P of A and B.

20
Exercise 96 (Solution 252). Let C be a category and T ∈ C0 a terminal object. For
any object A ∈ C0 , construct a product of A and T .
Hint: to form an idea what the object A × T should be, solve the exercise first in a
specific category, e.g., in the category of sets or in a category coming from a preordered
set.
Exercise 97 (Solution 253). Let C be a category and A, B ∈ C0 be objects. Show
that the product of A and B exists if and only if the following category has a terminal
object:
• The objects are triples (P, pl : P → A, pr : P → B).
• A morphism from (P, pl , pr ) to (Q, ql , qr ) is a morphism f ∈ C0 such that the
following diagram commutes:

P
pl pr
f

A ql Q qr B

• The composition and identity is inherented from the structure of C.


Exercise 98 (Solution 254). Let C be a category with a choice of product (A ×
B, πl , πr ) for any two objects A, B ∈ C0 . Given morphisms f : A → C and g : B → D
in C, construct a morphism
f × g : A × B → C × D.
Exercise 99 (Solution 255). Let C be a category with a choice of product (A ×
B, πl , πr ) for any two objects A, B ∈ C0 . For any A, B ∈ C0 , construct an isomorphism
A×B ∼
= B × A.

3.4. (Binary) Coproducts


Definition 100. Let C be a category and let A, B ∈ C0 be objects of C.
A triple (C, ιl : A → C, ιr : B → C) is called a coproduct of A and B if for any
triple (D, il : A → D, ir : B → D) there is exactly one morphism f : C → D such that
the following diagram commutes:
ιl ιr
A C B
f
il ir
D

If A and B have a specified coproduct (C, ιl : A → C, ιr : B → C), then the object


C is often called A + B. The morphism f : A + B → D determined by (D, il , ir ) is
denoted by [il , ir ].

21
Exercise 101. Write a sequence of suitable exercises about coproducts.
Exercise 102. Consider the category with one object and the rational numbers Q as
morphisms. Can you construct an initial object in this category? A terminal object?
Products? Coproducts?
Remark 103. Initial and terminal objects and products and coproducts are special
cases of limits and colimits. We are not studying, in these notes, the general notion
of (co)limit. However, the examples above should suffice for you to understand, in
your own time, other (co)limits, such as
• pullbacks and pushouts;
• products and coproducts of families of objects (not just of pairs of objects); and
• equalizers and coequalizers.
Further Reading. We do not discuss here whether/when/how (co)limits can be trans-
ported along functors. You can find some information on this in [7, §5.3].

4. Functors
An important aspect in computer programming is the transformation of data. For
example, if you have a data type X, then one can consider also the data type List(X)
of lists with values in X. If one thinks of the objects in a category to be data types,
then we can ask even more. If f : X → Y is a function (between the data types), then
this also induces a function from the X-valued lists to the Y -valued lists as follows:

List(f ) : List(X) → List(Y ) (1)


[x1 , . . . xn ] 7→ [f (x1 ), . . . , f (xn )].

Remark 104. The “. . . ” above are informal — a formal definition would define
List(f ) by structural recursion on lists, of course.
A functor formalizes this phenomenon:
Definition 105. Let C and D be categories. A functor F from C to D consists of
the following data:
• A function
C0 → D0 ,
written as X 7→ F (X).
• For each X, Y ∈ C0 , a function

C(X, Y ) → D(F (X), F (Y )),

written as f 7→ F (f ).

22
Moreover, this data should satisfy the following properties:
• (Preserves composition) For f ∈ homC (X, Y ) and g ∈ homC (Y, Z), we have
F (g ◦ f ) = F g ◦ F f .
• (Preserves identity) For X ∈ C, we have F (IdX ) = IdF (X) .
Example 106. The list-functor (on sets), denoted by List, is the functor from Set
to Set defined by the following data:
• The function on objects is given by:

Set0 → Set0 : X 7→ List(X).

• For each X, Y ∈ Set, the function on morphisms is given by

Set(X, Y ) → Set(List(X), List(Y )) : f 7→ List(f ),

where List(f ) is given in Eq. (1).


Exercise 107. Show that List is a functor, that is, show that it preserves identity
and composition of functions. Hint: use structural induction on lists.
Exercise 108. Consider the function Maybe0 : Set0 → Set0 sending a set X to
X + {∗}. For any two sets X and Y and f : X → Y , define a function

Maybe(f ) : Maybe0 X → Maybe0 Y

and show that this assignment satisfies the functor laws.


Exercise 109. Let A ∈ Set0 . Construct a functor (×A) : Set → Set that, on objects,
is given by
(×A)X := X × A.
Exercise 110. Let C be a category with chosen products, and let A ∈ C0 . Construct
a functor (×A) : C → C that, on objects, is given by

(×A)X := X × A.

Exercise 111. Let A ∈ Set0 . Construct a functor (+A) : Set → Set that, on objects,
is given by
(+A)X := X + A.
Exercise 112. Let C be a category with chosen coproducts, and let A ∈ C0 . Construct
a functor (+A) : C → C that, on objects, is given by

(+A)X := X + A.

Exercise 113. Let R ∈ Set0 be a set. Construct a functor (R →) : Set → Set that,
on objects, is given by
(R →)X := R → X.

23
Exercise 114. Let C be a category and let R ∈ C0 . Construct a functor C(R, −) :
C → Set that, on objects, is given by

(C(R, −))X := C(R, X).

Exercise 115. Let (X, ≤X ) and (Y, ≤Y ) be posets. Can you characterize/describe
the functors from Pos(X, ≤X ) to Pos(Y, ≤Y ) ? Before writing out the definitions,
what would you expect the answer to be?
Exercise 116. Let C be a category with chosen products (A × B, πA , πB ) for any two
objects A and B. Construct a functor

(×) : C × C → C

from the product category C × C to C. The objects of C × C are pairs of objects in


C, and morphisms (C × C)((X, X ′ ), (Y, Y ′ )) are pairs (f : X → Y, f ′ : X ′ → Y ′ ) of
morphisms in C.
Exercise 117. Let C be a category with chosen coproducts (A + B, ιA , ιB ) for any
two objects A and B. Construct a functor

(+) : C × C → C

from the product category C × C to C.


Exercise 118. Let (M, m, e) be a monoid and let Monoid(M, m, e) be its correspond-
ing category as defined in Definition 19. Can you characterize/describe the functors
from Monoid(M, m, e) to Set?

4.1. Categories as objects of a category?


Notice that a functor is a function between categories which preserves the structure
of a category. So by the philosophy of category theory, this would define a category
whose objects are categories and whose morphisms are functors. In order to make this
precise, we would also need a identity functor and we should have a composition of
functors.
Example 119. Let C be a category. The identity functor on C, denoted by IdC , is
the functor specified by the following data:

• The function on objects is given by

C0 → C0 : X 7→ X.

• For each X, Y ∈ C, the function on morphisms is given by

C(X, Y ) → C(X, Y ) : f 7→ f.

24
Exercise 120. Show that IdC (defined in Example 119) satisfies the properties of a
functor, i.e. IdC is indeed a functor.
Example 121. Let C, D and E be categories and F : C → D and G : D → E functors.
The composition functor of F with G, denoted by F · G, is the functor specified
by the following data:
• The function on objects is given by

C0 → E0 : X 7→ G(F (X)).

• For each X, Y ∈ C, the function on morphisms is given by

C(X, Y ) → E(G(F (X)), G(F (Y ))) : f 7→ G(F (f )).

Exercise 122. Show that F · G (defined in Example 121) satisfies the properties of a
functor, i.e. F · G is indeed a functor.
Definition 123. The Category of categories, denoted by Cat, is the category
specified by the following data:
• An object is a category.
• If C, D ∈ Cat are categories, then is Cat(C, D) the collection of all functors from
C to D.
• The identity morphism on a category C is the identity functor on C defined in
Example 119.
• The composition of morphisms, i.e. functors, is the composition of functors
defined in Example 121.
Exercise 124. Show that Cat satisfies the property of a category, i.e. Cat is indeed
a category.
Remark 125. When showing that Cat is a category, one is forced to consider equality
of objects when showing that two functors are equal. This goes against the spirit of
category theory, where we only ever consider equality of (parallel) morphisms. We
want to consider two objects “the same” when they are isomorphic, not when they
are equal. Of course, any two equal objects are isomorphic to each other, but not the
other way round; for instance, in the category of sets, the cartesian product A × B is
isomorphic to B × A, but they are not equal.
To stay within the spirit of category theory, one can instead consider Cat as a
bicategory.2 In a bicategory, one has one more layer of things: objects, morphisms,
and 2-cells between parallel morphisms. One also calls objects “0-cells” and morphisms
“1-cells”, for consistency. Importantly, in a bicategory, the laws concerning 1-cells (as
2 See,e.g., https://ncatlab.org/nlab/show/bicategory#detailedDefn for a definition of bicate-
gories.

25
stated in Definition 1) do not hold up to equality, but only up to isomorphism of
2-cells.
An important example is the bicategory given by the following data, which we only
list partially:
1. 0-cells are categories;
2. 1-cells are functors;
3. 2-cells are natural transformations (see Section 5);
4. composition and identity of 1-cells is composition and identity of functors.
We do not delve into bicategories in these notes; an introductory text is, for instance,
Leinster’s [6].

5. Natural transformations
Definition 126. Let F, G : C → D be functors. A natural transformation α from
F to G consists of the following data:
• For each X ∈ C0 , a morphism αX ∈ D(F (X), G(X)).
Moreover, this data should satisfy the following naturality condition:
For each f ∈ C(X, Y ), the following diagram should commute:
αX
F (X) G(X)
F (f ) G(f )

F (Y ) αY G(Y )
Moreover, we call α a natural isomorphism if for each X ∈ C0 , we have that αX is
an isomorphism in D.
Notation 127. If F, G : C → D are functors. A natural transformation α from F to
G, is denoted as α : F ⇒ G or
F

C α D

Example 128. (Currying) Let X be a set. Let F := Set(X, −) × X : Set → Set


be the functor induced by the following data (on objects):
Y 7→ Set(X, Y ) × X.
The evaluation defines a natural transformation ev : F ⇒ IdSet as follows:
evY : Set(X, Y ) × X → Y : (f, x) 7→ f (x).
Show that this indeed satisfies the naturality condition.

26
5.1. Functor categories
Definition 129. Let F : C → D be a functor. The identity natural transforma-
tion IdF on F is given by the following data:

∀X ∈ C0 : (IdF )X := IdF (x) .

Exercise 130. Show that for any functor F : C → D, the identity natural transfor-
mation IdF satisfies the properties of a natural transformation.
Definition 131. Let F, G, H : C → D be functors and α : F ⇒ G, β : G ⇒ H
be natural transformations. The (vertical) composition of α and β is the natural
transformation ·αβ is given by the following data:

∀X ∈ C0 : (β ◦ α)X := βX ◦ αX .

Exercise 132. Show that for any functors F, G, H : C → D and α : F ⇒ G, β : G ⇒ H


natural transformations, the (vertical) composition of α and β satisfies the properties
of a natural transformation.
Definition 133. Let C, D be categories. The category of functors or the functor
category from C → D, denoted by F un(C, D) or [C, D], is given by the following data:
• An object is a functor F : C → D.
• A morphism from F to G is a natural transformation α : F ⇒ G.
• The identity morphism on F is given by the identity natural transformation IdF
defined in Definition 129.
• The composition of F and G is given by the composition β ◦ α defined in Defi-
nition 131.
Exercise 134. Show that for any two categories C and D, the functor category from
C to D satisfies the properties of a category.
Definition 135. Let F, G : C → D and F̃ , G̃ : D → E be functors and α : F ⇒ G, β :
F̃ ⇒ G̃ be natural transformations. The horizontal composition (also called the
Godement product) of α and β, denoted by β • α, is defined as:

∀X ∈ C0 : (β • α)X := βG(X) ◦ F̃ (αX ). (2)

Exercise 136. Show that α • β (defined as in Definition 135), is indeed a natural


transformation.
Exercise 137. Show the following property:

∀X ∈ C0 : (β • α)X = G̃(αX ) ◦ βF (X) .

Hint: Write the equality as a (not-known commutative) square.

27
5.2. Exercises
Exercise 138. Let (M, m, e) be a monoid and let Monoid(M, m, e) be its corre-
sponding category. Recall from Exercise 118 that a functor from M to Set is a set X
together with an action of M on X, i.e. a function µ : M × X → X such that

∀x ∈ X : µ(e, x) = x, ∀n1 , n2 ∈ M, x ∈ X : µ(n1 , µ(n2 , x)) = µ(m(n1 , n2 ), x).

We will call a set X with an action of M on X an M -set. Characterize the natural


transformations between M -sets.
Exercise 139. Let (X, ≤X ) and (Y, ≤Y ) be posets. Recall from Exercise 115 that
a functor between posets corresponds with an order-preserving function, i.e. x1 ≤X
x2 =⇒ f (x1 ) ≤Y f (x2 ). Characterize the natural transformations between order-
preserving functions.

5.3. Equivalence of categories


Recall that objects X, Y ∈ C0 are isomorphic if there exist morphisms f ∈ C(X, Y )
and g ∈ C(Y, X) such that g ◦ f = IdX and f ◦ g = IdY . So in particular we have the
notion of an isomorphism in the category Cat of categories. Spelled out, this means
categories C and D are isomorphic if there exist functors F : C → D and G : C → D
such that G ◦ F = IdC and F ◦ G = IdD .
However, the following exercise shows that isomorphism of categories is not the correct
notion of equivalence/sameness between categories:
Let FinSet be the category whose objects are given by finite sets and whose morphisms
are given by functions3 . That this is a category follows since Set is a category.
Let FinOrd be the category whose objects are given by sets of the form

[n] := {0, 1, · · · , n − 1} ,

and whose morphisms are given by functions between these sets.


Every finite set X is always in bijection with a set of the form [n] (where n is the size
|X| of X). For each set X, we fix a bijection φX : X → [|X|]. Consequently, we have
a functor:
Definition 140. Let U : FinSet → FinOrd be the functor specified by the following
data:

• For X ∈ FinSet0 , we define U (X) := [|X|].


• For f ∈ FinSet(X, Y ), we define U (f ) : [|X|] → [|Y |] as the unique function
such that the following diagram commutes:

3 Notice that the objects of FinSet form a subset of the objects of Set, but given any two finite sets
X, Y inFinSet0 , we have F IN SET (X, Y ) = SET (X, Y ). We say in this case that FinSet is a
(full) subcategory of Set.

28
φX
X [|X|]
f U(f )

Y [|Y |]
φY

Exercise 141. Show that U : FinSet → FinOrd is indeed a functor. In particular,


you have to show that U is well-defined on the morphisms.
In order to show that U is not an isomorphism, one can use the following lemma/ex-
ercise:
Exercise 142. Show that a functor F : C → D is an isomorphism if and only if F
satisfies the following properties:
• F is injective on objects, i.e.

∀X, Y ∈ C0 : F (X) = F (Y ) =⇒ X = Y.

• F is surjective on objects, i.e.

∀Y ∈ D0 : ∃X ∈ C0 : F (X) = Y.

• F is faitful, i.e. the following functions are injective


FX,Y
∀X, Y ∈ C0 : C(X, Y ) −−−→ D(F (X), F (Y )) : f 7→ F (f )

• F is full, i.e. for all X, Y ∈ C0 , FX,Y is surjective.


Exercise 143. Show that U is not an isomorphism, i.e. state which part of an
isomorphism fails and give a concrete example that it fails.
Remark 144. So the problem with U (in the sense that it is not an isomorphism) is
that multiple (finite) sets are mapped to the same set. For this reason, a good notion
of equivalence between categories should not be injective on objects. Also, which is
not clear from this example, we should also weaken the condition of F being surjective
on objects. Instead, we need that F is essentially surjective on objects:

∀Y ∈ D0 : ∃X ∈ C0 : F (X) ∼
= Y.

So motivated by the remark, we define:


Definition 145. Categories C and D are equivalent if there exists a pair of functors
(F : C → D, G : D → C) such that there exists natural isomorphisms

G ◦ F → IdC , F ◦ G → IdD

So although U is not an isomorphism, it does induce an equivalence of categories:

29
Exercise 146. Show that U induces an equivalence of categories.
Exercise 147. Let C be the category whose objects are categories with a unique object
and whose morphisms are functors between these one-object categories, i.e. C is the
(full) subcategory of Cat generated by the categories with a unique object. Show that
C is equivalent to the category Monoid of monoids.
What happens if we do not consider C to consist of those categories with a unique
object, but with a unique object up to isomorphism, i.e. C is the category whose
objects are categories D which satisfy the following property:

∀X, Y ∈ D0 : X ∼
= Y.

The following exercise gives a characterization of a functor being an equivalence.


However, in order to show this, one has to use the axiom of choice which means
(informally) that if the following property holds:

∃x : P (x),

then we can fix some x such that P (x) holds.


Exercise 148. Show that a functor F : C → D induces an equivalences of categories
if and only if it is essentially surjective on objects and fully faithful.

6. Adjunctions
Definition 149. A pair (F, G) of functors F : C → D, G : D → C is called an adjoint
pair if for every objects C ∈ C0 and D ∈ D0 , there exists a bijection

αC,D : D(F (C), D) → C(C, G(D)),

which are moreover natural in both C and D, i.e. for each f ∈ C(C1 , C2 ) and g ∈
D(D1 , D2 ), the following diagrams commute:
αC2 ,D
D(F (C2 ), D) C(C2 , G(D))
−◦F (f ) −◦f (3)

D(F (C1 ), D) αC1 ,D C(C1 , G(D))


αC,D1
D(F (C), D1 ) C(C, G(D1 ))
G(g)◦− g◦− (4)

D(F (C), D2 ) αC,D2 C(C, G(D2 ))

If (F, G) is an adjoint pair, we call F the left adjoint of G and we call G the right
adjoint of F and we denote F ⊣ G.

30
Exercise 150. Let F : C → D be a functor. Show that if F has a left (resp. right)
adjoint G, then G must be unique up to isomorphism4 .
Exercise 151. Let U : Monoid → Set be the forgetful functor (defined in Exam-
ple 263) which maps a monoid to its underlying set and let F : Set → Monoid be
the functor which maps a set to the free monoid of this set (defined in Example 266).
Then is (F, U ) an adjoint pair. (Hint: Use Proposition 268).
Exercise 152. Let Y be a set. Show that the functor (induced by the following
mapping on objects)
− × Y : Set → Set : X 7→ X × Y,
has a right adjoint which is given by the functor (induced by the following mapping
on objects)
Set(Y, −) : Set → Set : X 7→ Set(Y, X).
Is there an analoguous statement in the category LEAN instead of Set?
Theorem 153. Let (F, G) be a pair of functors F : C → D, G : D → C. The following
statements are equivalent:
1. (F, G) is an adjoint pair.
2. There exists natural transformations

η : IdC ⇒ G ◦ F, ǫ : F ◦ G ⇒ IdD ,

such that for all C ∈ C and D ∈ D the following diagrams commute:

F (ηC ) ηG(D)
F (C) F (G(F (C))) G(D) G(F (G(D)))
ǫF (C) G(ǫC )
IdF (C) IdG(D)
F (C) G(D)

In case (F, G) satisfies these (equivalent) conditions, we call η the unit of the ad-
junction and ǫ the counit of the adjunction. The equalities in condition 2 are
called the triangle identities.
Proof. First assume that (F, G) is an adjoint pair. We have to define the unit and
counit and show that the triangle identities hold:
• Unit: For each X ∈ C0 , we should first define ηX ∈ C(X, G(F (X))). Since
F ⊣ G, we have a bijection

αX,F X : D(F X, F X) → C(X, G(F (X))),

4 Isomorphism w.r.t the functor category.

31
hence, we define ηX := αX,F X (IdF X ). We now show that (ηX )X∈C0 forms a nat-
ural transformation: Assume f ∈ C(X, Y ). We have to show that the following
diagram commutes:
αX,F X (IdF X )
X G(F (X))
f G(F (f ))

Y G(F (Y ))
αY,F Y (IdF Y )

That this square is indeed commutative follows from the following computation:

α(IdF Y ) ◦ f = α(IdF Y ◦ F (f )) = α(F (f )) = α(F (f ) ◦ IdF X ) = G(F (f )) ◦ α(IdF x ),


(5)
where the first and last equality hold by naturality of α.
• Counit: For each Y ∈ D0 , we the counit ǫY ∈ D(F (G(Y )), Y ) is defined as the
image of IdG(Y ) of the bijection

α−1
GY,Y : C(GY, GY ) → D(F (G(Y )), Y ).

That ǫ indeed forms a natural transformation is analoguous to the computation


in Eq. (5).
• Triangle identities: Both the triangle identities are proved analoguously, hence
we will only show the first triangle identity, i.e. IdF X = ǫF X ◦ F (ηX ). Unfolding
the definition of ǫ, this is equivalent to showing:

IdF X = α−1
GF X,F X (IdGF (X) ) ◦ F (ηX ).

Since the components of α are bijections, this is equivalent to showing

α(IdF X ) = α(α−1
GF X,F X (IdGF (X) ) ◦ F (ηX ))

This indeed holds by the following computation:

α(α−1
GF X,F X (IdGF (X) ) ◦ F (ηX )) = α(α
−1
(IdGF X )) ◦ ηX = IdGF X ◦ ηX = ηX ,

where the first (resp. second) equality holds by naturality (resp. bijectiveness)
of α.
This concludes the proof of (1) =⇒ (2). Now assume that (2) holds. We have to
construct bijections
αX,Y : D(F (X), Y ) → C(X, G(Y )),
which are natural in X and Y . Let g ∈ D(F (X), Y ). Define αX,Y (g) as the composite:

ηX G(g)
X −−→ G(F (X)) −−−→ G(Y ).

32
For the other direction, let f ∈ C(X, G(Y )). Define α−1
X,Y (f ) as the composite:

F (f ) Y ǫ
F X −−−→ F (G(Y )) −−→ Y.

That α and α−1 are inverses of eachother follows from the following computation:

α(α−1 (f )) = α(ǫY ◦ F (f )) = G(ǫY ◦ F (f )) ◦ ηX by definition,


= (GǫY ◦ GF (f )) ◦ ηX by functoriality of G,
= GǫY ◦ (GF (f ) ◦ ηX ) by associativity,
= GǫY ◦ (ηGY ) ◦ f by naturality of η
= (GǫY ◦ ηGY ) ◦ f by associativity
= f by triangle identity.

The other equality is shown analoguous by using functoriality of F , naturality of ǫ and


the other triangle identity.
It remains to show the naturality of α in both x and y which is left to the reader as
a good exercise on diagram chasing.

7. Monads and Effects


Recall that a monad (as defined, e.g., in Haskell) is a function m :: ∗ −> ∗ together
with the additional data of a function pure :: a −> m a (for each type a) and a function
(>>=) :: m a −> (a −> m b) −> m b (for types a and b).
The operations pure and (>>=) are expected to satisfy the following laws: such that
they satisfy the following properties:
1. t >>= pure == t
2. pure(x) >>= f == f x
3. (t >>= f) >>= g == t >>= (\x −> f x >>= g)
However, these laws cannot be enforced in Haskell, since Haskell does not have any
infrastructure for logic.
In a category, however, we can define monads including the monad laws. We will
actually give two different definitions of monad; one called “Kleisli triple” (Defini-
tion 154), which corresponds to what is called “monad” in Haskell, and one called
“monad” (Definition 162). The formulation of monads uses that the arguments to
(>>=) can be reordered.

Definition 154. A Kleisli triple over a category C is consisting of the following


data:
• A function T : C0 → C0 .
• For each X ∈ C0 , a morphism ηX ∈ C(X, T (X)).

33
• For each f ∈ C(X, T (Y )), a morphism f ∗ ∈ C(T (X), T (Y )).
such that the following properties holds:

1. For each X ∈ C0 , we have ηX = IdT (X) .
2. For each f ∈ C(X, T (Y )), the following diagram commutes:

ηX
X T (X)
f∗
f

T (Y )

3. For each f ∈ C(X, T (Y )) and g ∈ C(Y, T (Z)), the following diagram commutes:

f∗
T (X) T (Y )
g∗
(g∗ ◦f )∗
T (Z)

We denote a Kleisli triple as (T, η, (−)∗ ).


Exercise 155. Convince yourself that the operations and laws of a Kleisli triple
correspond, in the category Hask, to the operations and properties of a monad in
Haskell.
Exercise 156 (Solution 234). Show how the following assignment induces a Kleisli
triple over the category Set:
X 7→ List(X).
The resulting monad is called the List monad.
Exercise 157 (Solution 235). Show how the following assignment induces a Kleisli
triple over the category Set:
X 7→ BinTree(X),
where BinTree(X) is the set of binary trees labelled with elements from X at the
leaves, that is the set inductively generated by the constructors leaf : X → BinTree(X)
and branch : BinTree(X) → BinTree(X) → BinTree(X). The resulting monad is
called the Tree monad.
Exercise 158 (Solution 236). Let E be a set (considered as a set of exceptions). Show
how the following assignment induces a Kleisli triple over the category Set:

X 7→ (X + E),

The resulting monad is called the Exception monad.

34
Exercise 159 (??). Show how the following assignment induces a Kleisli triple over
the category Set:
X 7→ Pf in (X) := {A ⊆ X | A is finite} .
The resulting monad is called the Monad of nondeterminism.
Exercise 160 (Solution 238). Let R be a set (considered as a set of results). Show
how the following assignment induces a Kleisli triple over the category Set:

X 7→ ContR (X) := (X → R) → R.

The resulting monad is called the Continuation monad.


Exercise 161 (Solution 239). Let R be a set. Show how the following assignment
induces a Kleisli triple over the category Set:

X 7→ R → X

The resulting monad is called the Monad of families of elements.


The notion of a Kleisli triple can equivalently be described as follows:
Definition 162. A monad over a category C consists of the following data:
• A (endo)functor T : C → C.
• A natural transformation η : IdC ⇒ T .
• A natural transformation (“multiplication”) µ : T ◦ T ⇒ T .
such that for each X ∈ C0 the following diagrams commute:
µT (X) ηT (X) T (µX )
T 3 (X) T 2 (X) T (X) T 2 (X) T (X)
T (µX ) µX µX
IdT (X) IdT (X)
2 T (X)
T (X) µX T (X)

where we denote T 2 := T ◦ T and T 3 := T ◦ T ◦ T .


Exercise 163. Given a monad, construct a Kleisli triple from it. Conversely, given a
Kleisli triple, construct a monad from it.
Exercise 164. For each of the Kleisli triples above, describe the monad multiplication
µ obtained from it.
Every Kleisli triple induces a category:
Definition 165. Let (T, η, (−)∗ ) be a Kleisli triple over C. The Kleisli category,
denoted by CT , is the category defined by the following data:
• (CT )0 := C0 .

35
• For each X, Y ∈ (CT )0 , CT (X, Y ) := C(X, T Y ).
• The identity on X ∈ (CT )0 is ηX .
• The composition of f ∈ CT (X, Y ) and f ∈ CT (Y, Z) is g ∗ ◦ f .
Exercise 166. Show that for every Kleisli triple, its Kleisli category satisfies the
properties of a category.

8. Inductive Datatypes and Initial Algebras


8.1. Examples
Exercise 167. Consider the datatype
data N ::=
| zero : N
| succ : N → N
and the following category:
• Objects are triples (X, z ∈ X, s : X → X) with X a set/type;
• Morphisms from (X, z ∈ X, s : X → X) to (X ′ , z ′ ∈ X ′ , s′ : X ′ → X ′ ) are
functions f : X → X ′ such that the following diagrams commute:
z s
1 X X X
f f f
z′
′ ′ s′
X X X′

• Composition and identity are given by composition of functions in Set. (Check


that this is well-defined, that is, that the composition of two functions making
the above diagrams commute makes the right diagrams commute again.)
Show that the triple (N, zero, succ) is an initial object in this category.
Exercise 168. Consider the datatype
d a t a Exp : : =
| Int : Z → Exp
| Plus : Exp × Exp → Exp
| S q u a r e d : Exp → Exp
and consider the following category:
• Objects are quadruples (X, I : Z → X, P : X → X → X, S : X → X) with X a
set/type;

36
• Morphisms from (X, I, P, S) to (X ′ , I ′ , P ′ , S ′ ) are functions f : X → X ′ such
that the following diagrams commute:

I P S
Z X X ×X X X X
f f ×f f f f
I′
′ ′
P S
X′ X′ × X′ X′ X′ X′

• Composition and identity are given by composition of functions in Set. (Check


that this is well-defined.)
Show that the quadruple consisting of the type Exp together with the functions Int ,
Plus, and Squared, is an initial object in this category.

8.2. Datatypes as Initial Algebras


Further Reading. This chapter is strongly inspired by Varmo Vene’s Ph.D. thesis
[10, Chapter 2].
A good explanation of recursion on lists is given in Graham Hutton’s tutorial paper
[5].
In this section we introduce (initial) algebras which allows us to define inductive
data types.
Definition 169. Let F : C → C be an endofunctor. An F -algebra consists of the
following data:
1. An object C ∈ C0 .
2. A morphism φ ∈ C(F (C), C).
Intuition 170. An algebra is roughly a set equipped with some operations, such as
multiplication. The arities, that is, the inputs, of the operations are determined by
the functor F . An important class of functors are polynomial functors built using
the coproduct (+) and the product (×). Intuitively, the different summands of a
polynomial functor each correspond to one datatype constructor, whereas the use of
the product indicates that a constructor takes several inputs.
Example 171. Let Maybe : Set → Set be the endofunctor given on objects by
Maybe(X) := 1 + X. A Maybe-algebra is a pair (X, φ) of a set X and a function
φ : 1 + X → X. By the universal property of the coproduct, φ is given, equivalently,
by two functions z and s as follows.

z:1→X
s:X →X

Here, think of “z” standing for “zero”, and “s” standing for “successor”.

37
Example 172. Let F be the endofunctor induced by:

F : Set → Set
X 7→ 1 + (X × X).

An F -algebra consists of a set X ∈ Set together with a function φ : Set(1 + (X ×


X), X). Since φ is function from the disjoint union, we have that φ corresponds
uniquely to two functions:

e:1→X
m : X × X → X.

This is precisely the data of a monoid.


Conversely, if (M, m, e) is a monoid, then this induces a function
φ=[φe ,φm ]
1 + (M × M ) −−−−−−−→ M,

defined by pattern matching as follows:

φe : 1 → M
⋆ 7→ e
φm : M × M → M
(x, y) 7→ m(x, y)

The pair (M, φ) is an F -algebra.


Remark 173. Note that a monoid (M, m, e) also satisfies some laws. The laws are
not expressed in Example 172. To incorporate the laws, one studies instead algebras
of a monad.
Definition 174. Let F : C → C be an endofunctor and (C, φ) and (D, ψ) be F -
algebras. A (F -algebra) homomorphism from (C, φ) to (D, ψ) is a morphism f ∈
C(C, D) such that the following diagram commutes:
φ
FC C
Ff f

FD ψ
D

Exercise 175. Let F be the endofunctor defined as in Example 172, i.e. the endo-
functor whose algebras corresponds with monoids. Characterize the F -algebra homo-
morphisms.
Definition 176. Let F : C → C be an endofunctor. The category of F -algebras,
denoted by Alg(F ), is defined by the following data:
• The objects are the F -algebras.

38
• The morphisms are the F -algebra homomorphisms.
• The identity on (C, φ) is given by the identity IdC in C.
• The composition is given by the composition of morphisms in C.
Exercise 177. 1. Draw two diagrams to illustrate Definition 176.
2. Show that Alg(F ) satisfies the properties of a category.
We are interested in initial objects of Alg(F ), if they exist. We call these “initial
F -algebras”. For a general endofunctor F , an initial F -algebra does not exist; but for
many interesting choices of F , such an initial object does exist. Before coming to the
general definition (see Definition 179), we consider an example.
Exercise 178. Consider the functor Maybe : Set → Set.
1. Show that the initial Maybe-algebra is given by the pair (N, [zero, succ]), where
N is the set of natural numbers, and zero : 1 → N and succ : N → N are the
function picking out zero and the successor function, respectively.
2. Given any other Maybe-algebra (X, [z, s]), unpack what it means for the square
of Definition 174 to commute.
3. Compare the data from the previous exercise to a definition of a function f :
N → X by pattern matching (e.g., in Haskell).
Definition 179. Let F : C → C be an endofunctor. An initial F -algebra (if it
exists) is an initial object in Alg(F ). Unfolding the definition, this means that it is an
F -algebra (µF , in) such that for any F -algebra (C, φ), there exists a unique morphism
LφM ∈ C(µF , C) such that the following diagram commutes:

in
F µF µF
F LφM LφM
(6)

FC φ
C

A morphism of the form LφM is called a catamorphism.


Exercise 180 (Solution 256). Let F : C → C be an endofunctor and let (µF , in) be
an initial algebra. Show that
LinM = IdµF .
Exercise 181. Let Bool be the inductive data type generated by the following two
constructors:
True : B o o l
F a l s e : Bool

39
Define an endofunctor F : Set → Set such that the F -algebras can be characterized
as triples (X, b1 , b2 ) with X a set and b1 , b2 ∈ X.
Moreover, show that (Bool, true, f alse) is the initial object in Alg([)F ].
Exercise 182. The disjoint union (i.e. the coproduct) of two sets X and Y can also
be characterized as an inductive data type, indeed: It is generated by the following
two constructors:
f : X −> X+Y
g : Y −> X+Y
Define an endofunctor F : Set → Set such that the F -algebras can be characterized
as triples (C, il , ir ) with C a set and il : X → C, ir : Y → C be functions.
Moreover, show that (X + Y, inl, inr) is the initial object in Alg(F ), where X + Y is
the disjoint union of X and Y (i.e. the coproduct in Set) and inl : X → X + Y, inr :
Y → X + Y the canonical inclusions.
Exercise 183. Let Nc be the conatural numbers, i.e. N + {∞}. Consider the maybe
endofunctor (defined in Example 171), i.e. the functor induced by

F : Set → Set : X 7→ 1 + X.

The functions

zeroc : 1 → Nc :⋆ 7→ 0,
(
n + 1, if x := n ∈ N,
succc : Nc → Nc :x 7→
∞, if x := ∞.

form an F -algebra. However, show that (Nc , zeroc , succc ) is not a initial F -algebra.
Exercise 184 (Fusion Property, Solution 257). Let F : C → C be an endofunctor
and let (µF , in) be an initial algebra. Show that for F -algebras (C, φ) and (D, ψ) and
f ∈ C(C, D), we have

f ◦ φ = ψ ◦ F (f ) =⇒ f ◦ LφM = LψM.

This is summarized in the following diagram:


in
F µF µF
F LφM LφM
(7)
F LψM FC φ
C LψM

Ff f

FD ψ
D

Exercise 185 (Lambek’s theorem). Let F : C → C be an endofunctor and let


(µF , in) be an initial algebra. Then in is an isomorphism whose inverse is given by
in−1 = LF (in)M.

40
Exercise 186 (Solution 258). Let C be a category with an initial object ⊥. Show
that (⊥, Id⊥ ) is the initial algebra for the identity (endo)functor on C.
Exercise 187. Let A be a set and define F to be the functor induced by

FA : Set → Set
X 7→ 1 + (A × X).

1. Show that an FA -algebra consists of a triple (X, n, c), where X is a set, n ∈ X


is an element of X, and c : A × X → X is a function.
2. Show that the initial FA -algebra is given by the set List(A) of A-valued lists,
together with constants nil ∈ List(A) and cons : A × List(A) → List(A).
3. Given any other FA -algebra (X, n, c), unpack what it means for the square of Def-
inition 174 to commute. Compare it to a definition of a function f : List(A) → X
by pattern matching.

Remark 188. In the case of lists, the operator L M is also known as fold , which in
Haskell is defined as follows:
fold : : (a → b → b) → b → ([ a ] → b)
fold f v [] = v
f o l d f v ( x : xs ) = f x ( f o l d f v xs )

Compare the input of fold to the data of an FA -algebra given in Item 1 of Exercise 187.
Exercise 189. Define the following functions as a catamorphism, that is, using fold .
In each case, draw the diagram corresponding to Diagram 6 of Definition 179.
1. sum :: [ Int ] → Int
2. product :: [ Int ] → Int
3. and :: [Bool ] → Bool
4. or :: [Bool ] → Bool
5. (++) :: [a] → [a] → [a]

6. length :: [a] → Int


7. reverse :: [a] → [a]
8. map :: (a → b) → ([ a] → [b])
9. filter :: (a → Bool ) → ([ a] → [a])
Solutions are given in [5, §2].
Hint: a systematic approach to reformulating functions on lists defined by explicit
recursion in terms of fold is described in [5, §3.3].

41
Exercise 190 ([5, §3.1]). Show that (+1) . sum = fold (+) 1, by showing that (+1) . sum
makes Diagram 6 of Definition 179 commute.
Exercise 191. An exercise about (the limits of) representing functions as catamor-
phisms (or rewriting functions using ‘fold‘):
1. We can represent numbers as big-endian binary numbers, in the set List({0, 1}):
the lists with elements in the set {0, 1}. For example, 13 becomes [1, 1, 0, 1],
which we represent as (cons 1 (cons 1 (cons 0 (cons 1 nil )))) . We define the func-
tion bin2int : List({0, 1}) → N, that converts big-endian binary representa-
tions to positive integers. For example, ( bin2int (cons 1 (cons 0 nil ))) = 2 and
( bin2int (cons 1 (cons 1 (cons 0 (cons 1 nil ))))) = 13.
Show that we can give bin2int as a catamorphism. i.e. with F the functor for
which List({0, 1}) is an initial algebra, show that there exists an F -algebra (N, f )
such that Lf M = bin2int.
2. We can also represent a number as a little-endian binary number. Then 13
becomes [1, 0, 1, 1], which we represent as (cons 1 (cons 0 (cons 1 (cons 1 nil )))) .
We define the function bin2int2 : List({0, 1}) → N, that converts little-endian
binary representations back to positive integers.
Why can’t we give bin2int2 as a catamorphism?
(Hint: how would such a catamorphism calculate the values for [1], [0, 1] and
[0, 0, 1]?)
3. Show that there exists an F -algebra (N × N, f ) such that πl ◦ Lf M = bin2int2,
with πl the projection on the first coordinate.
Exercise 192. Let A be a set and define F to be the functor induced by

FA : Set → Set : X 7→ A ⊔ (X × X).

Show that the initial FA -algebra is given by the set BT ree(A) of A-valued binary
trees.
Remark 193. Notice that in Exercise 187 and Exercise 192, we can consider the
functor FA as a bifunctor where we vary A, i.e.

F : Set → Set → Set : (A, X) 7→ FA (X).

In particular, under the assumption that for every A ∈ Set the initial FA -algebra
exists, we can wonder if the assignment

Set0 → Set0 : A 7→ µFA ,

can be extended to a functor. The following exercise answers this question positively
for arbitrary categories.

42
Exercise 194 (Solution 259). Let F : C → C → C be a bifunctor such that for any
object A ∈ C, the initial algebra for the functor induced by
FA : C → C : X 7→ F (A, X),
exists. Show how
C0 → C0 : A 7→ µFA ,
induces a functor.

9. Fusion Property
The fusion property of Exercise 184 can be used to “fuse” a composition of functions
into one function, possibly leading to more efficient code.
We are going to exemplify this using the datatypes of lists and of natural numbers.
Recall that (N, [zero, succ]) is the initial Maybe-algebra. We also write (+1) for succ.
Further Reading. The content of this section is very much inspired by [5, §3.2]. You
are strongly encouraged to read that section before reading the present section. In this
section, we show how
Exercise 195 ([5, §3.2]). Show that (+1) . sum = fold (+) 1, by using the fusion prop-
erty of Exercise 184.
P
Solution 196. We also write for sum. Note that sum is defined as the catamorphism
L[zero, (+)]M. The situation is summarized in the following diagram

[nil,cons]
{∗} + N × List(N) List(N)

P P
Id+Id×

[zero,(+)]
{∗} + N × N N L[1,(+)]M

Id+Id×(+1) (+1)

[1,(+)]
{∗} + N × N N

PIn order to show that (+1) . sum = fold (+) 1, in the diagram expressed as (+1) ◦
= L[1, (+)]M, we need to show that the lower rectangle commutes—this is what
Exercise 184 says.
There are two cases to consider: the case of ∗, and the case of a pair (m, n) ∈ N × N.
In the case of ∗, we obtain
(+1) 0 = 1
and in the case of (m, n), we obtain
(+1) ((+) m n) = (+) m ((+1) n)
both of which hold.

43
Exercise 197. Prove that map g . map f = map (g . f) using the fusion property.
Further Reading. In Sections 8 and 9, we have only looked at functions defined via
iteration, that is, functions defined as catamorphisms of some F -algebra. While prim-
itive recursive functions can always be expressed as a catamorphism via tupling (see,
e.g., [5, §4] and [10, §3.1]), it is more natural specify them via a slightly more sophis-
ticated universal property, explained in detail in Vene’s dissertation [10, Chapter 3].
The interested reader might also study the tutorial by Fokkinga [3] or the paper by
Meijer et al. [8].
A guide to further literature on recursion operators is given in [5, §6].

10. Terminal Coalgebras and Coinductive Datatypes


Further Reading. We only give a brief introduction to (terminal) coalgebras in this
section. A more systematic exploration of the topic is given in [8].
In this section we introduce (terminal) coalgebras which allows us to define coin-
ductive data types.
Definition 198. Let F : C → C be an endofunctor. An F -coalgebra consists of the
following data:
• An object C ∈ C.
• A morphism φ ∈ C(C, F (C)).
Notice that an F -algebra consists of a morphism F (C) → C, while an F -coalgebra
consists of a morphism C → F (C) in the other direction.
Definition 199. Let F : C → C be an endofunctor and (C, φ) and (D, ψ) be F -
coalgebras. A (F -coalgebra) homomorphism from (C, φ) to (D, ψ) is a morphism
f ∈ C(C, D) such that the following diagram commutes:

φ
C F (C)
f F (f )

D ψ
F (D)

Exercise 200. Define the category CoAlg(F ) of F -coalgebras analogously to the cat-
egory Alg(F ) of F -algebras (as in Definition 176).

Definition 201. Let F be an endofunctor on C. The terminal F -coalgebra is the


terminal object in CoAlg(F ) which we denote by (ν F , out).
For (C, φ) an arbitrary F -coalgebra, we denote the unique morphism (C, φ) →
(ν F , out) by JφK, and we call a morphism of this form an anamorphism (instead of
a catamorphism as in Definition 179).

44
Exercise 202. Spell out what it means for a coalgebra to be the terminal coalgebra.
Exercise 203. Let F : C → C be an endofunctor and assume that the terminal
coalgebra (ν F , out) exists. Show that the following properties holds:
1. Id = JoutK.
2. For F -algebras (C, φ) and (D, ψ) and f ∈ C(C, D), we have

ψ ◦ f = F (f ) ◦ φ =⇒ JψK ◦ f = JφK.

This is summarized in the following diagram:


φ
C FC
f Ff
F JφK
JφK D ψ
FD
JψK F JψK

out
νF F νF

Exercise 204. (Dual Lambek’s theorem) Let F : C → C be an endofunctor and


let (ν F , out) be a terminal coalgebra. Then is out an isomorphism whose inverse is
given by out−1 = JF (out)K.
Exercise 205. Let C be a category with an terminal object ⊤. Then (⊤, Id⊤ ) is a
terminal coalgebra for the identity (endo)functor on C.
Exercise 206 (Solution 260). Let F be the functor induced by

F : Set → Set : X 7→ 1 + X.

Show that the terminal F -coalgebra is given by the following data:


• The underlying object is given by the set N + {∞} of natural numbers with
infinity.
• The underlying function is given by the predecessor defined as follows:

N + {∞} → 1 + N + {∞}
0 7→ ⋆
s(n) 7→ n
∞ 7→ ∞

where ⋆ is the unique element of 1.


Example 207 (Streams). The codata type of streams over a given set A is given by
the terminal coalgebra (ν FA , out) of the functor FA (X) := A × X. We write Stream(A)

45
for ν FA . The functions head : Stream(A) → A and tail : Stream(A) → Stream(A) are
given by

head = πl ◦ out : Stream(A) → A


tail = πr ◦ out : Stream(A) → Stream(A)

respectively. Put differently (recall the definition of the product in Definition 86), we
have
out = hhead, taili : Stream(A) → A × Stream(A)
Given any two functions

h:C→A
t:C→C

the anamorphism Jhh, tiK is the unique solution f : C → Stream(A) of the equation
system

head ◦ f = h
tail ◦ f = f ◦ t

that is, the unique function f : C → Stream(A) making the following square commute:
hh,ti
C A×C
Jhh,tiK Id×Jhh,tiK
hhead,taili
Stream(A) A × Stream(A)

Exercise 208 (Solution 261). Define, as an anamorphism, the function nats : N →


Stream(N) which returns the stream of all natural numbers starting with the natural
number given as the argument
Exercise 209 (Solution 262). Define, as an anamorphism, the function zip : Stream(A)×
Stream(B) → Stream(A × B) that zips the argument streams together.

11. Solutions
Solution 210 (Exercise 12). The inequality x ≤ y (resp. y ≤ x) means that we have
a (unique) morphism from f ∈ hom(x, y) (resp. g ∈ hom(y, x)). Consequently, we get
a loop g ◦ f ∈ hom(x, x). Since the hom-sets are either empty or a singleton, we have
g ◦ f = Idx . Hence, antisymmetry means that if IdX = g ◦ f for some f ∈ hom(x, y)
and g ∈ hom(y, x), we must have

x = y, f = Idx = g.

Rephrased a little bit different, we get: The category Pre(X, ≤) has no non-trivial
loops if (X, ≤) is antisymmetric.

46
Solution 211 (Exercise 15). That Pos would be a preorder-category means that each
of the hom-sets is either empty or a singleton. Hence, it is not a preorder-category if
there exists (X, ≤X ) and (Y, ≤Y ) such that Pos((X, ≤X ), (Y, ≤Y )) has more then one
element.
We choose (X, ≤) := (N, ≤) =: (Y, ≤). A morphism f ∈ Pos((N, ≤), (N, ≤)) consists
of a function f : N → N such that the following property holds:

∀n, m ∈ N : n ≤ m =⇒ f (n) ≤ f (m).

But there are a lot of functions from N to N which satisfies this property, indeed: For
any k ∈ N, we have that
fk : N → N : n 7→ n + k,
is a morphism in Pos. Hence Pos((N, ≤), (N, ≤)) consists of an infinite amount of
distinct morphisms.
Solution 212 (Exercise 21). A category C is of the form (M, m, e) if and only if C
has a unique object. Indeed, if C has a unique object, lets denote this by X, then we
can define a monoid (M, m, e) as follows:
• The underlying set of the monoid is M := C(X, X).
• The multiplication m is given by m(f, g) := g ◦ f .
• The identity element e is given by e := IdX .
That (M, m, e) is indeed a monoid, i.e. satisfies the monoid laws, is just a translation
of the axioms of C being a category.
Solution 213 (Exercise 22). Since a monoid consists of a set M together with a binary
operation m : M → M → M (called the multiplication) and a identity element e ∈ M ,
a suitable morphism of monoids, from (M1 , m1 , e1 ) to (M2 , m2 , e2 ) should consists of
a function f : M → N which preserves the structure (i.e. the multiplication and the
identity element). More precisely:
• Preservation of the multiplication:

∀x, y ∈ M1 : f (m1 (x, y)) = m2 (f (x), f (y)).

• Preservation of the identity:


f (e1 ) = e2 .

We will now prove that the monoids (as objects) and morphisms of monoids (as the
morphisms) carry the data of a category, i.e. we have to define identity morphisms
and the composition of morphisms:

• Let (M, m, e) be a monoid. The identity morphism is given by the identity


function IdM on the underlying set M .

47
• Let (Mi , mi , ei ) be a monoid for i = 1, 2, 3 and let

f : (M1 , m1 , e1 ) → (M2 , m2 , e2 ), g : (M2 , m2 , e2 ) → (M3 , m3 , e3 )

be morphisms of monoids. The composition g ◦ f of f and g is defined as the


composition of the underlying functions.
Before we show that this data satisfies the properties of a category, we first have to
show that everything is well-defined, i.e. that the identity is a morphism of monoids
and that the composition of morphisms of monoids is again a morphism of monoids:
• That the identity is a morphism of monoids follows by the following calculations:

∀x, y ∈ M : IdM (m(x, y)) = m(x, y) = m(IdM (x), IdM (y)),


IdM (e) = e.

The equalities holds because IdM is the identity function on M .


• That the composition of morphism of monoids is again a morphism of monoids
follows by the following calculations:
– Composition preserves multiplication: for any x, y ∈ M1 , we have

g ◦ f (m1 (x, y)) = g (f (m1 (x, y)))


= g (m2 (f (x), f (y)))) (f preserves mult.)
= m3 (g(f (x)), g(f (y))) (g preserves mult.)
= m3 (g ◦ f (x), g ◦ f (y))

Composition preserves identity element by:

g ◦ f (e1 ) = g(f (e1 )) = g(e2 ) = e3 ,

where the second (resp. third) equality holds since f (resp. g) preserves
the identity element.
So everything is indeed well-defined. So we are now ready to show that composition
of some morphism of monoids f with the identity morphism is again f (both on
the left and right) and that the composition of morphisms of monoids is associative.
This follows immediate since everything is defined using functions and we know that
functions satisfy these properties.
Solution 214 (Exercise 23). In order to make C into a category, we have to define
the identity morphisms and the composition of morphisms.
Let n ∈ N =: C0 be a natural number. The identity on n is an element in C(n, n),
which is the set of n × n-matrices. Hence, for the identity on n, we can take Idn to be
the identity n × n-matrix, i.e. all coefficients are zero except on the diagonal where
everything is 1.

48
Let l, m, n ∈ N be natural numbers and M (resp. N ) be a l × m-matrix (resp.
m × n-matrix). The composition N ◦ M should be an l × n-matrix, hence we define
N ◦ M as the matrix multiplication of M and N , i.e. N ◦ M = M · N .
That this data satisfies the properties of being a category follows immediate because
matrix multiplication is associative and that the multiplication of any matrix M with
the identity matrix (of the right size and both on the left or on the right) is again M .
Solution 215 (Exercise 24). In order to avoid confusion, we use the following notation:
For any f ∈ C(X, Y ) morphism, we denote by f op the corresponding morphism in
C op (Y, X).
Let X ∈ C op 0 = C0 . The identity morphism is defined as the morphism correspond-
op
ing to the identity, i.e. it is (IdX ) .
Let g ∈ C (Z, Y ), f ∈ C (Y, X). The composition is defined as: f op ◦ g op :=
op op op op
op
(g ◦ f ) .
That this data satisfies the properties of a category, follows because C is a category,
indeed:
• That the left unit law holds follows by the right unit law of C as follows:
op
f op ◦ Id op = (Id ◦ f ) = f op ,

where the first equality holds by definition of the opposite composition and the
second holds by the right unit law of C.
The right unit law holds analoguously by the left unit law of C.
• That the associativity holds follows by the associativity of C as follows:
op
(f op ◦ g op ) ◦ hop = (g ◦ f ) ◦ hop
= (h ◦ (g ◦ f ))op
op
= ((h ◦ g) ◦ f ) by associativity of C,
= f op ◦ (h ◦ g)op
= f op ◦ (g op ◦ hop )

Solution 216 (Exercise 31). Any preordered set (X, ≤) can be described by a graph
where the vertices are given by the elements of X and there exists an edge from x to
y if and only if x ≤ y. Hence, if we denote by G the corresponding graph of (X, ≤),
we have that Pos(X, ≤) = Graph(G).
In particular we have that the number of edges is either 0 or 1. Hence, a category gen-
erated by a graph comes from a preordered set if and only if the number of morphisms
in any fixed hom-set is either 0 or 1.
If (X, ≤) is a poset, i.e. we have antisymmetry, then we have that the corresponding
graph (and consequently the corresponding category) have no (non-trivial) loops.
Solution 217 (Exercise 34). That f : a → b is an isomorphism with inverse g means
precisely that g ◦ f = Ida and f ◦ g = Idb . But stating that g is an isomorphism with
inverse f means precisely those conditions. Hence, this hold by definition.

49
Solution 218 (Exercise 35). Let f : a → b be an isomorphism. That f has a unique
inverse means that if g, h : b → a are morphisms such that

g ◦ f = Ida , f ◦ g = Idb , h ◦ f = Ida , f ◦ h = Idb

then we must have g = h.


So assume g and h satisfy the condition of being an inverse of f . Then we have:

g= Idb ◦ g , by left unit law,


= (h ◦ f ) ◦ g , since h is inverse of f ,
= h ◦ (f ◦ g) , by associativity,
= h ◦ Ida , since g is inverse of f
= h , by right unit law

Solution 219 (Exercise 36). Let f : a → b and g : b → c be isomorphisms. Denote


their (unique) inverses by f −1 and g −1 . We have to show that there exists a morphism
h : c → a such that
h ◦ (g ◦ f ) = Ida , (g ◦ f ) ◦ h = Idc .
We define h := f −1 ◦ g −1 . The left equality then holds by the following computation:

h ◦ (g ◦ f ) = (f −1 ◦ g −1 ) ◦ (g ◦ f )
= f ◦ (g −1 ◦ g) ◦ f −1 by associativity,
= f ◦ Idb ◦ f −1 since g −1 inverse of g,
= f ◦ f −1 by unit law,
= Ida since f −1 inverse of f .

The right equality holds analoguously.


Solution 220 (Exercise 38). The Haskell datatype Bool is given by:
d a t a B o o l = True | F a l s e
In order to construct a (Haskell) function f from BW to Bool, it suffices to define
f (Black) and f (W hite).
The first isomorphism, denoted by f1 , is given by f1 (Black) = T rue and f1 (W hite) =
F alse. Its inverse (denoted by g1 ) is given by g1 (T rue) = Black and g1 (F alse) =
W hite. To show that these are inverse, we have to show

g1 (f1 (W hite)) = W hite, g1 (f1 (Black)) = Black.

These equalities holds by definition of f1 and g1 .


The second isomorphism, denoted by f2 , is given by f2 (Black) = F alse and f2 (W hite) =
T rue. Its inverse (denoted by g2 ) is given by g2 (F alse) = Black and g1 (T rue) =
W hite. That g2 is the inverse of f2 is also immediate.
Solution 221 (Exercise 39). The isomorphisms in Set are precisely the bijective
functions, indeed:

50
• Assume f : X → Y is a bijection, i.e.
∀y ∈ Y : ∃!xy ∈ X : f (x) = y
We show that the inverse of f is given by:
g : Y → X : y 7→ xy .
So we have to show g ◦ f = IdX and f ◦ g = IdY . Let x ∈ X, since that
g(f (x)) is the unique element z ∈ X such that f (z) = f (x) (and since x satisfies
this condition), we have g(f (x)) = x. Since this holds for all x ∈ X, we have
g ◦ f = IdX .
Let y ∈ Y and let x := xy be the unique element in X such that f (x) = y. So
by definition of g, we have g(y) = x, hence f (g(y)) = f (x) = y.
• Assume f : X → Y is an isomorphism with inverse f −1 . Let y ∈ Y , we have to
show that there exists a unique x ∈ X such that f (x) = y. Define x := g(y).
Since f ◦ g = IdY , we have y = f (g(y)) = f (x), hence, this x indeed satisfies the
condition. To show that x is unique, let z ∈ X satisfy f (z) = y. That z = x
now follows from g ◦ f = IdX , indeed: z = g(f (z)) = g(y) = x.
Solution 222 (Exercise 40). The isomorphisms in Pos are precisely the bijections
f : (X, ≤X ) → (Y, ≤Y ) such that
x1 ≤X x2 ⇐⇒ f (x1 ) ≤Y f (x2 ), (8)
Indeed:
• Assume f is a bijection which satisfies Eq. (8). Since it is a bijection, we know (by
the solution to Exercise 39), that there exists a function g : (Y, ≤Y ) → (X, ≤X )
such that g ◦ f = Id(X,≤X ) and f ◦ g = Id(Y,≤Y ) . However, this does not conclude
the proof of the first implication, because we do not know appriori, that g is a
morphism of posets. So we have to show
∀y1 , y2 ∈ Y : y1 ≤Y y2 =⇒ g(y1 ) ≤X g(y2 ).
Let y1 , y2 ∈ Y . Since f is bijective, there exist x1 , x2 ∈ X such that f (x1 ) = y1
and f (x2 ) = y2 . If f (x1 ) = y1 ≤Y y2 = f (x2 ), then by Eq. (8), we also have
that x1 ≤ x2 . But by definition of g, we have g(y1 ) = x1 and g(y2 ) = x2 ,
hence g(y1 ) ≤X g(y2 ) which shows that g is an order-preserving morphism, i.e.
g ∈ Pos((Y, ≤Y ), (X, ≤X )).
• Assume f is an isomorphism in Pos with inverse g. Since f is a function which
satisfies g ◦ f = Id(X,≤X ) and f ◦ g = Id(Y,≤Y ) , we have (by the same argument as
in the solution to Exercise 39), that f is a bijection. Hence, it remains to show
that Eq. (8) holds. Let x1 , x2 ∈ X.
If x1 ≤X x2 , then we have f (x1 ) ≤Y f (x2 ) since f ∈ Pos((X, ≤X ), (Y, ≤Y )).
Assume f (x1 ) ≤Y f (x2 ). Since g ∈ Pos((Y, ≤Y ), (X, ≤X )), we have g(f (x1 )) ≤X
g(f (x2 )). But g ◦ f = IdX , hence x1 ≤X x2 .

51
Solution 223 (Exercise 41). First, let (X, ≤Y ) be a preorder. A morphism f : x → y
is an isomorphism if and only if there exists a morphism g : y → x such that g ◦ f = Idx
and f ◦ g = Idy . But, in a preorder category, each hom-set has a unique element if it is
non-empty. So, for any g ∈ hom(y, x) and f ∈ hom(x, y), we always have g ◦ f = Idx
and f ◦ g = Idy . Hence a morphism f : x → y in a preorder-category is an isomorphism
if and only if there exists a morphism g : y → x. The existence of a morphism f : x → y
means precisely that x ≤ y. Hence, isomorphisms in a preorder-category corresponds
with a pair of elements (x, y) in X such that x ≤ y and y ≤ x.
If (X, ≤X ) is a poset, i.e. satisfies antisymmetry, then if x ≤ y and y ≤ x, we must
have x = y. Consequently, in a poset-category, the only isomorphisms are the identity
morphisms (i.e. corresponding with x ≤ x).
Solution 224 (Exercise 46). Consider
b o o l 2 I n t : : B o o l −> I n t
bool2Int False = 0
b o o l 2 I n t True = 1
We can go back, so that we get False and True from 0 and 1:
i n t 2 B o o l : : I n t −> B o o l
i n t 2 B o o l n | n == 0 = False
| o t h e r w i s e = True
However, notice that not only 1 is converted back to True, but also everything other
than 0 is converted to True.
We have
Int2Bool ( bool2Int y) = y
for every y :: Bool, but we don’t have bool2Int (int2Bool x) = x for all x :: Int .
We can say that there is enough room in the type integers for it to host a copy of
the type of booleans, but there isn’t enough room in the type of booleans for it to host
a copy of the type of integers.
But notice that there are other ways in which the type Bool lives inside the type Int
as a retract: for example, we can send False to 13 and True to 17, and then send back
everything bigger than 15 to True and everything else to False .
Solution 225 (Exercise 49). The monomorphisms in Set correspond precisely with
the injective functions, i.e. the functions f : X → Y which satisfy
∀x1 , x2 ∈ X : f (x1 ) = f (x2 ) =⇒ x1 = x2 ,
Indeed:
• Assume f is injective. Let g, h : Z → X be functions such that f ◦ g = f ◦ h. We
have to show g = h, i.e.
∀z ∈ Z : g(z) = h(z).
Since f is injective, it suffices to show
∀z ∈ Z : f (g(z)) = f (h(z)).
But this holds by the condition of g and h. Hence, f is indeed a monomorphism.

52
• Assume f is a monomorphism. We have to show that for each x1 , x2 ∈ X, we
have f (x1 ) = f (x2 ). Let 1 = {⋆} be a singleton set and define

g1 : 1 → X : ⋆ 7→ x1 , g2 : 1 → X : ⋆ 7→ x2 ,

Since f (x1 ) = f (x2 ), we have f ◦ g1 = f ◦ g2 . But f is a monomorphism, hence


g1 = g2 which means x1 = g1 (⋆) = g2 (⋆) = x2 . Thus, f is indeed injective.
Solution 226 (Exercise 52). Let f : X → Y be a section with a retraction h : Y → X,
i.e. h ◦ f = IdY . By Exercise 49, it suffices to show that f is a monomorphism. Let
g1 , g2 : Z → X be morphisms in Set such that f ◦ g1 = f ◦ g2 . We have to show
g1 = g2 ,, this follows from the following computation:

g1 = IdY ◦ g1 by unit law,


= h ◦ f ◦ g1 since f section,
= h ◦ f ◦ g1 by associativity,
= h ◦ f ◦ g2 by assumption,
= h ◦ f ◦ g2 by associativity,
= IdY ◦ g2 since f section,
= g2 by unit law.

Notice that this proof shows that in an arbitrary category, a section is always a
monomorphism.
Solution 227 (Exercise 54). Let f : a ∼
= b be an isomorphism with inverse f −1 . There
are multiple proofs which one can give, an abstract one (which is indirect in the sense
that we use another exercise/lemma) and a more direct one.
• Indirect proof: By the solution of 52, we know that any section (from a section-
retraction pair) is a monomorphism. An analoguous argument shows that any
retraction (section-retraction pair) is an epimorphism. Hence it suffices to show
that f is both a section and a retraction, but this is immediate because f −1 ◦ f =
Ida and f ◦ f −1 = Idb .
• Direct proof: We first show that f is a monomorphism. Assume g1 , g2 : c → a
are morphisms such that f ◦ g1 = f ◦ g2 . We then have that g1 = g2 because

g1 = Ida ◦ g1 = (f −1 ◦ f ) ◦ g1 since f : a ∼
= b,
= f −1 ◦ (f ◦ g1 ) by associativity,
= f −1 ◦ (f ◦ g2 ) by assumption,
= (f −1 ◦ f ) ◦ g2 by associativity
= Ida ◦ g2 since f : a ∼
=b
= g2 .

53
That f is also an epimorphism is analoguous, indeed: Assume g1 , g2 : b → c are
morphisms such that g1 ◦ f = g2 ◦ f . We then have that g1 = g2 because

g1 = g1 ◦ Idb = g1 ◦ (f ◦ f −1 ) since f : a ∼
= b,
= (g1 ◦ f ) ◦ f −1 by associativity,
= (g2 ◦ f ) ◦ f −1 by assumption,
= g2 ◦ (f ◦ f −1 ) by associativity
= g2 ◦ Idb since f : a ∼
=b
= g2 .

Solution 228 (Exercise 55). Let (X, ≤X ) be a preordered set. Any morphism f ∈
Pos(X, ≤X )(x, y) is always both a monomorphism and an epimorphism because hom-
sets have at most on element. But, by Exercise 41, we know that in a poset (not a
preordered set!), the only isomorphisms are the identity morphisms. Hence, if x ≤ y
but x 6= y (living in a poset), then the corresponding morphism in hom(x, y) is both
an epimorphism and monomorphisms but not an isomorphism.
A concrete example is given by e.g. the poset of truth values {0, 1}. We have 0 ≤ 1
and those are not equal.
Solution 229 (Exercise 65). An initial object (and the only one), is the emptyset ∅,
indeed: Let X be a set. Then there is clearly a unique function ∅ → X.
Solution 230 (Exercise 67). A initial object in Pos(X, ≤) is the minimal object, that
is an element ⊥ ∈ X such that

∀y ∈ X : ⊥ ≤ y. (9)

Indeed: Assume x is an initial object in (X, ≤), i.e. for any other element y ∈ X, there
exists a (unique) morphism x → y, i.e. hence, by definition of the hom-sets, we have
x ≤ y. So x is indeed the minimal object.
Conversely, assume ⊥ is a minimal element, hence, for each y ∈ X, we have ⊥ ≤ y.
Hence hom(⊥, y) is non-empty. So it must contain exactly one element. This means
precisely that it is initial.
A somewhat more compact solution is as follows: By definition of Pos(X, ≤), for
each x ∈ X, we have:

∀y ∈ X : (x ≤ y ⇐⇒ ∃!f ∈ hom(x, y)) .

Hence an object x is initial if and only if, x ≤ y for all y ∈ X, if and only if it is
minimal.
Solution 231 (Exercise 68). Let A and B be initial objects in C. By initiality of A
(resp. B), there exists a unique morphism f ∈ C(A, B) (resp. g ∈ C(B, A)). That
f and g are inverses follows because g ◦ f ∈ C(A, A) (resp. f ◦ g ∈ C(B, B)). But
by initiality of A (resp. B), C(A, A) (resp. C(B, B)) has a unique element, but both
g ◦ f, IdA ∈ C(A, A) (resp. f ◦ g, IdB ∈ C(B, B)), hence they must be equal.

54
Solution 232 (Exercise 69). Assume A ∈ C0 is initial, B ∈ C0 an arbitrary object and
i:A∼ = B an isomorphism. We have to show that B is initial, i.e. for each X ∈ C0 ,
there should exists a unique morphism B → X.
Fix such an X. By initiality of A, there exists a (unique) morphism f ∈ C(A, X).
If we denote the inverse of i by j, we have f ◦ j ∈ C(B, X). To show that f ◦ j is the
unique morphism in this hom-set, let g ∈ C(B, X). So we have g ◦ i ∈ C(A, X). By
initiality of A, we have g ◦ i = f . The claim now follows by the following computation:
f ◦ j = (g ◦ i) ◦ j = g ◦ (i ◦ j) = g ◦ IdB = g.
Solution 233 (Exercise 71). We give three solutions to this exercise.
• Consider the category generated by the graph:
x y
This category can not have an initial object since there is no morphism from x
to y or vice versa.
• Consider the category generated by the graph:
f
x g y
This category also can not have an initial object, indeed: There is no morphism
from y to x, hence y can not be initial. But also x can not be initial since f and
g are different morphisms.
• Consider the category Pos(Z, ≤), i.e., the category
... −2 −1 0 1 2 ...
This category can not have an initial object: Suppose it has an initial object
x ∈ Z. Then we have another object x − 1 ∈ Z. Since x is initial, we have a
morphism x → x − 1, which means that x ≤ x − 1, which is absurd. Therefore,
this category does not have an initial object.
Solution 234 (Exercise 156). For any set X, we write
(+) : List(X) × List(X) → List(X)
for list concatenation.
For each set X ∈ Set0 , we define:
ηX : X → List(X) : x 7→ [x] := cons(x, nil).
For each function f ∈ Set0 (X, List(Y )), we define, by list recursion, the following
function:
f ∗ : List(X) → List(Y ) (10)
nil 7→ nil (11)
cons(x, xs) 7→ f x + f ∗ xs (12)
We now show that the properties of a Kleisli triple hold:

55

1. For each set X, we have to show ηX = IdT (X) , that is, for a list ℓ ∈ List(X), we

show ηX (ℓ) = ℓ. We prove this by structural induction on the list ℓ.

In case ℓ = nil, we have, by Eq. (11), that ηX (nil) = nil.
In case ℓ = cons(x, xs), we compute
∗ ∗
ηX (cons(x, xs)) = ηX (x) + ηX (xs) by definition of (−)∗ ,
= ηX (x) + IdListX (xs) by induction hypothesis
= [x] + IdListX (xs) by definition of ηX
= [x] + xs
= cons(x, xs).

2. For each function f : X → Y , we have to show f ∗ (ηX (x)) = f (x), this indeed
holds by the following computation:

f ∗ (ηX (x)) = f ∗ (cons(x, nil)) = cons(f x, f ∗ (nil)) = cons(f x, nil),

where the first equality holds by definition of ηX and the second equality holds
by definition of f ∗ .
3. Let f : X → ListY and g : Y → ListZ be functions, we have to show

g ∗ (f ∗ (ℓ)) = (g ∗ ◦ f )∗ (ℓ),

for any ℓ ∈ ListX. We prove this by structural induction on the list ℓ.


• In case ℓ = nil, the equality holds trivially by Eq. (11).
• In case ℓ := cons(x, s). By definition of (f )∗ , the left hand side of is:

g ∗ (f ∗ (cons(x, s))) = g ∗ (f (x) + f ∗ (xs)),

and the right hand side is:

(g ∗ ◦ f )∗ (cons(x, s)) = g ∗ (f (x)) + (g ∗ ◦ f )∗ (xs) = g ∗ (f (x)) + g ∗ (f ∗ (xs)),

where the first equality holds by definition of (g ∗ ◦ f )∗ and the second


holds by the induction hypothesis. Hence it remains to show the following
equality:

g ∗ (f (x) + f ∗ (xs)) = g ∗ (f (x)) + g ∗ (f ∗ (xs)). (13)

We do a pattern matching on f (x) to show Eq. (13):


– In case f (x) = nil, we have

g ∗ (nil + f ∗ (xs)) = g ∗ (f ∗ (xs)) = nil + g ∗ (f ∗ (xs)) = g ∗ (nil) + g ∗ (f ∗ (xs)),

where the thirth equality holds by Eq. (11).

56
– In case f (x) = cons(y, u), with y ∈ Y and u ∈ ListY , we have:

g ∗ (cons(f (x), f ∗ (s)) = g ∗ (cons(cons(y, u), f ∗ (xs))),


= g ∗ (cons(y, u + f ∗ (xs))),
= g(y) + g ∗ (u + f ∗ (xs)),
= g(y) + g ∗ (u) + g ∗ (f ∗ (xs)),
= g ∗ (cons(y, u)) + g ∗ (f ∗ (xs)).

where the second equality holds by definition of cons, the thirth and
fifth by definition of g ∗ and the fourth by the induction hypothesis.
Solution 235 (Exercise 157). For each set X ∈ Set0 , we define:

ηX : X → BinTree(X) : x 7→ leaf(x).

For each function f ∈ Set0 (X, BinTree(Y )), we define:


(
∗ f (a) if t = leaf(a),
f : BinTree(X) → BinTree(Y ) : t 7→
branch(f ∗ (t1 ), f ∗ (t2 )) if t = branch(t1 , t2 ).

We now show that the properties of a Kleisli triple hold:



1. For each set X, we have to show ηX = IdBinTree(X) . We show this by pattern
matching on t:
• If t = leaf(a), then
∗ ∗
ηX (t) = ηX (leaf(a)) = ηX (a) = leaf(a) = t.

• If t = branch(t1 , t2 ), then
∗ ∗ ∗ ∗
ηX (t) = ηX (branch(t1 , t2 )) = branch(ηX (t1 ), ηX (t2 )) = branch(t1 , t2 ) = t.

2. For each function f : X → Y , we have to show f ∗ (ηX (a)) = f (a), this indeed
holds by the following computation:

f ∗ (ηX (a)) = f ∗ (leaf(a)) = f (a).

3. Let f : X → BinTreeY and g : Y → BinTreeZ be functions, we have to show

g ∗ (f ∗ (t)) = (g ∗ ◦ f )∗ (t).

That this equality holds follows by pattern matching:


• If t = leaf(a), then

g ∗ (f ∗ (t)) = g ∗ (f ∗ (leaf(a)) = g ∗ (f (a)) = (g ∗ ◦f )(a) = (g ∗ ◦f )∗ (leaf(a)) = (g ∗ ◦f )∗ (t).

57
• If t = branch(t1 , t2 ), then is the left-hand-side given by

g ∗ (f ∗ (t)) = g ∗ (f ∗ (branch(t1 , t2 ))) = g ∗ (branch(f ∗ (t1 ), f ∗ (t2 ))) = branch(g ∗ (f ∗ (t1 )), g ∗ (f ∗ (t2 ))).

The right-hand-side is given by

(g ∗ ◦ f )∗ (t) = (g ∗ ◦ f )∗ (branch(t1 , t2 )) = branch((g ∗ ◦ f )(t1 ), (g ∗ ◦ f )(t2 )).

Hence, by the induction hypothesis, the both sides are equal.


Solution 236 (Exercise 158). Before we continue with this exercise, we first fix some
notation. Since X+E is the disjoint union of X and E, we have the canonical inclusions
which we denote by

iX
l : X → X + E, iX
r : E → X + E.

Hence, a function whose domain is X + E is completely determined by specifiying


where each iX X
l (x) and each ir (e) are mapped to. Notice that this is precisely the
notation and the universal property of the coproduct (in Set).
For each set X ∈ Set0 , we define:

ηX : X → X + E : x 7→ iX
l (x).

For each function f ∈ Set0 (X, Y + E), we define:


(
∗ f (x) if z = iX
l (x),
f : X + E → Y + E : z 7→ Y X
ir (e) if z = ir (e).

We now show that the properties of a Kleisli triple hold:



1. For each set X, we have to show ηX = IdX+E :
• If z = iX
l (x), then

∗ ∗ X
ηX (z) = ηX (il (x)) = ηX (x) = iX
l (x) = z = IdX+E (z).

• If z = iX
r (e), then

∗ ∗ X
ηX (e) = ηX (ir (e)) = iX
r (e) = z = IdX+E (z).

2. For each function f : X → Y , we have to show f ∗ (ηX (x)) = f (x) but this holds
directly by the definition of (−)∗ since ηX (x) = iX
l (x).

3. Let f : X → Y + E and g : Y → Z + E be functions, we have to show

g ∗ (f ∗ (z)) = (g ∗ ◦ f )∗ (z).

To show this, we do pattern matching on z ∈ X + E:

58
• If z = iX
l (x), then

g ∗ (f ∗ (z)) = g ∗ (f ∗ (iX ∗ ∗ ∗ X ∗ ∗
l (x))) = g (f (x)) = (g ◦ f ) (il (x)) = (g ◦ f ) (z).

• If z = iX
r (e), then

g ∗ (f ∗ (z)) = g ∗ (f ∗ (iX ∗ Y Z ∗ ∗ X ∗ ∗
l (e))) = g (il (e)) = il (e) = (g ◦f ) (il (e)) = (g ◦f ) (z).

Solution 237 (Exercise 159). For each set X ∈ Set0 , we define:


ηX : X → Pf in (X) : x 7→ {x}.
For each function f ∈ Set0 (X, Pf in (Y )), we define:
[
f ∗ : Pf in (X) → Pf in (Y ) : A 7→ f (a).
a∈A

First notice that ηX and f ∗ are well-defined, indeed:


• ηX (x) = {x} is clearly finite since it only contains one element.
• Let A ∈ Pf in (X). By definition of f , for each
S a ∈ A, f (a) is finite. But there
are only a finite number of elements in A, so a∈A f (a) is a finite union of finite
sets, hence, it is again finite.
We now show that the properties of a Kleisli triple hold:

1. For each set X, we have to show ηX = IdPf in (X) . Let A ∈ Pf in (X), the claim
then follows by the following computation:
[ [

ηX (A) = ηX (a) = {a} = A = IdPf in (X) (A).
a∈A a∈A

2. For each function f : X → Y , we have to show f ∗ (ηX (x)) = f (x) but this holds
directly by the definition of (−)∗ since
[
f ∗ (ηX (x)) = f ∗ ({x}) = f (a) = f (x).
a∈{x}

3. Let f : X → Pf in (Y ) and g : Y → Pf in (Z) be functions, we have to show


g ∗ (f ∗ (A)) = (g ∗ ◦ f )∗ (A).
Let A ∈ Pf in (X), the left-hand-side is given as:
!
[ [ [ [
∗ ∗ ∗
g (f (A)) = g f (a) = g(f (a)) = g(f (a)).
S
a∈A b∈ a∈A f (a)
a∈A b∈f (a)

The right-hand-side is given as:


[ [ [ [
(g ∗ ◦ f )∗ (A) = (g ∗ ◦ f )(a) = g ∗ (f (a)) = g(f (a))
a∈A a∈A a∈A b∈f (a)

Hence, both sides are equal.

59
Solution 238 (Exercise 160). For each set X ∈ Set0 , we define:
ηX : X → (X → R) → R : x 7→ (λf.f (x)).
For each function f ∈ Set0 (X, ContR (Y )), we define:
f ∗ : ContR (X) → ContR (Y ) : i 7→ λ(j : Y → R), i(f (−)(j)).
Notice that this is indeed well-defined: Let i ∈ ContR (X), i.e. i : (X → R) → R.
Then f ∗ (i) : (Y → R) → R. Let j : Y → R. Then f (−)(j) : X → R, hence we can
apply it to i and we have i (f (−)(j)) ∈ R.
Let i ∈ ContR (X). We now show that this data satisfies the properties of a Kleisli
triple:

1. For each set X, we have to show ηX = IdContR (X) . Let x ∈ X. The claim then
follows by the following computation:

ηX (i) = λj, i (ηX (−)(j)) = λj, i (λx, j(x)) = i

2. For each function f : X → Y , we have to show f ∗ (ηX (x)) = f (x), this follows
by the following computation:
f ∗ (ηX (x)) = f ∗ (λg, g(x)) = λj, ((λg, g(x)) (f (−)(j))) = λj, (f (x)(j)) = f (x).

3. Let f : X → ContR (Y ) and g : Y → ContR (Z) be functions, we have to show


g ∗ (f ∗ (i)) = (g ∗ ◦ f )∗ (i).
The left-hand-side is given as:
g ∗ (f ∗ (i)) = g ∗ (λj, i (f (−)(j))) = λj̃, (λj, i (f (−)(j))) g(−)(j̃) = λj̃, i f (−) g(−)(j̃) .
 

The right-hand-side is given as:


(g ∗ ◦ f )∗ (i) = λj, i ((g ∗ ◦ f )(−)(j))
So to show that both sides are equal, it sufficies to show that for each j, we have
f (−) (g(−)(j)) = (g ∗ ◦ f )(−)(j).
Notice that these are functions X → R. Hence we will show this pointwise for
each x ∈ X. The left-hand-side is given by:
f (−) (g(−)(j)) (x) = f (x) (g(−)(j))
The right-hand-side is given by:
(g ∗ ◦ f )(−)(j)(x) = (g ∗ ◦ f )(x)(j)
= ((g ∗ ◦ f )(x)) (j)
= (g ∗ (f (x))) (j)
= (λk, f (x) (g(−)(k))) (j)
= f (x) (g(−)(j)) .
Hence, both sides are equal.

60
Solution 239 (Exercise 161). For each set X ∈ Set0 , we define:

ηX : X → (R → X) : x 7→ (λ , x).

For each function f ∈ Set0 (X, R → Y ), we define:

f ∗ : (R → X) → (R → Y ) : g 7→ λr, f (g(r))(r).

Notice that this is indeed well-typed: Let g : R → X and r ∈ R. Then g(r) ∈ X,


therefore, f (g(r)) : R → Y and consequently f (g(r))(r) ∈ Y .
We now show that this data satisfies the properties of a Kleisli triple:

1. For each set X, we have to show ηX = IdR→X . Let r ∈ R and g ∈ R → X. The
claim then follows by the following computation (using functional extensionality):

ηX (g)(r) = ηX (g(r))(r) = (λ , g(r))(r) = g(r).

2. For each x ∈ X and r ∈ R, we have to show f ∗ ◦ ηX = f . The claim then follows


by the following computation (using functional extensionality):

f ∗ (ηX (x))(r) = f ∗ (λ , x)(r) = (λr′ , f ((λ , x)(r′ ))(r′ )) (r) = f ((λ , x)(r))(r) = f (x)(r).

3. Let f : X → (R → Y ) and g : Y → (R → Z). We have to show, by function


extensionality, that for any φ ∈ R → X, we have

(g ∗ ◦ f )∗ (φ) = g ∗ (f ∗ (φ)).

This indeed follows, yet again by functional extensionality. Let r ∈ R. We


calculate both the left and right-hand side:

LHS =(g ∗ ◦ f )∗ (φ)(r)


=f ◦ g ∗ (φ(r))(r)
=g ∗ (f (φ(r))) (r)
=g (f (φ(r))(r)) (r).

RHS =g ∗ (f ∗ (φ))(r)
=g ∗ (λs, f (φ(s))(s)) (r)
=g(f (φ(r))(r))(r).

Thus, the left and right hand sides compute to the same term, hence they are
equal.
Solution 240 (Exercise 72). An initial object is a one-element set ({⋆}, ⋆). Let (X, x)
be a pointed set. Then we have a unique function ⋆ → X that sends ⋆, the chosen
(and only) point of {⋆}, to x, the chosen point of X, namely f : ⋆ 7→ x.

61
Solution 241 (Exercise 79). A terminal set in the category of sets is a one-element
set {⋆}. Given any set X, we have a unique function X → ⋆, since any element of X
must be sent to ⋆.
Solution 242 (Exercise 81). Given a poset (X, ≤), a terminal object in the category
Pos(X, ≤) is exactly a maximal element in X. Indeed, given such a maximal element
x ∈ X = Pos(X, ≤)0 , we have for all y ∈ Pos(X, ≤)0 , since x is maximal, that y ≤ x.
Therefore, we have a morphism f : x → y. By the definition of the hom-sets in
Pos(X, ≤), f is unique and we conclude that x is a terminal object. Conversely, un-
folding the definition of terminal object shows that a terminal object yields a maximal
element.
Solution 243 (Exercise 82). Suppose that we have a category C and two terminal
objects B, B ′ ∈ C0 . Since B ′ is terminal, we have a morphism f : B → B ′ and since
B is terminal, we have a morphism g : B ′ → B. Note that we have two morphisms
from B to B, namely g ◦ f and IdB . Also, because B is terminal, there exists a unique
morphism B → B. Therefore, g ◦ f = IdB . In the same way, we have f ◦ g = IdB ′ .
Therefore, f is the isomorphism (with inverse g) between B and B ′ that we are looking
for.
Solution 244 (Exercise 83). Let C be a category and take B, B ′ ∈ C0 objects in C.
Suppose that we have an isomorphism i : B ∼ = B ′ and that B is a terminal object in

C. We have to show that B is terminal. In other words, for all A ∈ C0 , we have to
show that there exists a unique morphism f : A → B ′ .
Now, given such an object A ∈ C0 , we have a morphism f : A → B by terminality
of B. Therefore, we have a morphism g = i ◦ f : A → B ′ . This proves existence. For
uniqueness, suppose that we also have another morphism h : A → B ′ . Then we have
morphisms i−1 ◦ g and i−1 ◦ h from A to B. Since B is terminal, there exists only one
morphism from A to B, so i−1 ◦ g = i−1 ◦ h. Therefore, we have

g = i ◦ (i−1 ◦ g) = i ◦ (i−1 ◦ h) = h

and this concludes the proof.


Solution 245 (Exercise 84). Let C be a category. Suppose that C has a terminal
object B ∈ C0 . Note that C0 = C op 0 . We will show that B is an initial object in C op .
That is, for all A ∈ C op 0 , we will show that C op has a unique morphism from B to A.
Let A ∈ C op 0 be an arbitrary object. Since B is terminal in C, we have that C(A, B)
contains exactly one element. Then C op (B, A) contains exactly one element as well,
because C(A, B) = C op (B, A). Therefore, B is an initial object in C op .
Conversely, suppose that C op has an initial object B ∈ C op 0 = C0 . Given any object
A ∈ C0 = C op 0 , since B is initial in C op , C op (B, A) contains exactly one element f .
Then C(A, B) contains exactly one element (this is f again) as well. Therefore, B is a
terminal object in C.
Solution 246 (Exercise 85). We give three solutions to this exercise.

62
• Consider the category generated by the graph:

x y

This category can not have a terminal object since there is no morphism from x
to y or vice versa.
• Consider the category generated by the graph:
f
x g y

This category also can not have a terminal object, indeed: There is no morphism
from y to x, hence x can not be terminal. But also y can not be terminal since
f and g are different morphisms.
• Consider the category Pos(N, ≤), i.e., the category

0 1 2 ...

This category can not have a terminal object: Suppose it has a terminal object
n ∈ N. Then we have another object n + 1 ∈ N. Since n is terminal, we have a
morphism n + 1 → n, which means that n + 1 ≤ n, which is absurd. Therefore,
this category does not have a terminal object.
Solution 247 (Exercise 91). Given A, B ∈ Set0 , we claim that the cartesian product
A × B with the left projection πl : (a, b) 7→ a and right projection πr : (a, b) 7→ b is a
product of A and B.
Indeed, given an object Q ∈ Set0 with morphisms l : Q → A and r : Q → B, we
have a morphism f := hl, ri : Q → A × B, given by q 7→ (l(q), r(q)). For all q ∈ Q,
we have πl ◦ f (q) = πl (l(q), r(q)) = l(q) and πr ◦ f (q) = πr (l(q), r(q)) = r(q), so the
diagram commutes, which proves existence.
Now, for uniqueness, suppose that we also have another morphism g : Q → A × B
that makes the diagram commute. Note that we can write all elements p ∈ A × B as
p = (πl (p), πr (p)). Then we have, for all q ∈ Q,

g(q) = (πl (g(q)), πr (g(q))) = (πl ◦ g(q), πr ◦ g(q)) = (l(q), r(q)) = f (q),

which completes the proof.


Solution 248 (Exercise 93). For a poset (X, ≤), note that morphisms between objects
always are unique if they exist, so uniqueness conditions on morphisms (and whether
diagrams commute or not) are not relevant here. Furthermore, any diagram commutes
automatically.
For objects A, B ∈ Pos(X, ≤)0 , a product of A and B is an object C ∈ Pos(X, ≤)0
with morphisms C → A and C → B such that for any object D ∈ Pos(X, ≤)0 with
morphisms D → A and D → B, we have a morphism D → C.

63
This means that we need an object C such that C ≤ A and C ≤ B, and for all
objects D such that D ≤ A and D ≤ B, we also have D ≤ C. Therefore, a product of
A and B is the (unique up to isomorphism) greatest element that is less than or equal
to A and B, if it exists.
Remark 249. The uniqueness up to isomorphism is necessary. For example, consider
the poset-category generated by the following diagram:
A B

X Y
For the product of A and B, the candidates are X and Y , since we have both X ≤ A
and X ≤ B, and Y ≤ A and Y ≤ B. However, X cannot be the product, since if we
are given D = Y , we need Y ≤ X, which is not true. In the same way, Y cannot be
the product, because X ≤ Y does not hold.
Solution 250 (Exercise 94). In a category C, given two objects A, B ∈ C0 , suppose
that we have two products C, C ′ ∈ C0 , with projections πl : C → A, πr : C → B,
πl′ : C ′ → A and πr′ : C ′ → B.
Since C ′ is a product, and we have the morphisms πl and πr , the universal property
gives a morphism f : C → C ′ such that πl = πl′ ◦ f and πr = πr′ ◦ f . In the same way,
we have a morphism g : C ′ → C such that πl′ = πl ◦ g and πr′ = πr ◦ g.
Since C is a product, the universal property gives that there is exactly one morphism
h : C → C such that πl ◦ h = πl and πr ◦ h = πr . The morphism h = IdC satisfies this
property. However, we also have the morphism g ◦ f : C → C, such that πl ◦ g ◦ f =
πl′ ◦ f = πl and πr ◦ g ◦ f = πr′ ◦ f = πr . Therefore, g ◦ f = h = IdC . In the same way,
f ◦ g = IdC ′ , so f : C ∼
= C ′ is an isomorphism, with inverse g.
Solution 251 (Exercise 95). Let C be a category and take objects A, B ∈ C0 . Let
(P, πl : P → A, πr : P → B) be a product of A and B in C. Let P ′ ∈ C0 be another
object, and suppose that we have an isomorphism f : P ∼ = P ′.
We claim that (P , πl , πr ), with πl = πl ◦ f and πr = πr ◦ f −1 is also a product of
′ ′ ′ ′ −1 ′

A and B. Now, given any object Q ∈ C0 with morphisms l : Q → A and r : Q → B,


we have to show that there exists a unique morphism g : Q → P ′ such that πl′ ◦ g = l
and πr′ ◦ g = r. See also the following diagram:

Q
l r
h

A πl P πr B
f
πl′ πr′

P
By the universal property of the product, we have a morphism h : Q → P such that
πl ◦ h = l and πr ◦ h = r. We take g = f ◦ h. We have
πl′ ◦ g = (πl ◦ f −1 ) ◦ (f ◦ h) = πl ◦ h = l

64
and
πr′ ◦ g = (πr ◦ f −1 ) ◦ (f ◦ h) = πr ◦ h = r.
This proves existence.
For uniqueness, suppose that we have two morphisms, g, g ′ : Q → P ′ such that
πl ◦ g = l = πl′ ◦ g ′ and πr′ ◦ g = r = πr′ ◦ g ′ . By the universal property of the product,

there exists exactly one morphism h : Q → P such that πl ◦ h = l and πr ◦ h = r. Since


πl ◦ (f −1 ◦ g) = (πl ◦ f −1 ) ◦ g = πl′ ◦ g = l
and
πr ◦ (f −1 ◦ g) = (πr ◦ f −1 ) ◦ g = πr′ ◦ g = r,
we have h = f −1 ◦ g. In the same way, we have h = f −1 ◦ g ′ . Therefore,
g = f ◦ f −1 ◦ g = f ◦ h = f ◦ f −1 ◦ g ′ = g ′ ,
which concludes the proof.
Solution 252 (Exercise 96). Let C be a category, let A ∈ C0 be an object and let
T ∈ C be the terminal object.
We claim that (A, πl , πr ) (with πl = IdA and πr the unique morphism A → T ) is a
product of A and T .
We have to prove that for all B ∈ C0 with morphisms l : B → A and r : B → T ,
there exists a unique morphism f : B → A such that πl ◦ f = l and πr ◦ f = r. To
that end, let B ∈ C0 be such an object with morphisms l and r.
To prove existence, we take f = l. Then we have πl ◦ f = IdA ◦ l = l. Since T is a
terminal object, the morphism B → T is unique, so l = πr ◦ f .
To prove uniqueness of f , suppose that there exists also another morphism, f ′ :
B → A such that πl ◦ f ′ = l. Then we have
f ′ = IdA ◦ f ′ = πl ◦ f ′ = l = f,
which concludes the proof.
Solution 253 (Exercise 97). Let C be a category and A, B ∈ C0 objects. Let us call
the category mentioned in the exercise CA×B .
Suppose that we have a terminal object (C, πl , πr ) ∈ CA×B 0 . We claim that this
is a product of A and B in C. Indeed, given any object D ∈ C0 with morphisms
l : D → A, r : D → B, we have an object (D, l, r) ∈ CA×B 0 . Since (C, πl , πr ) is a
terminal object, there exists a unique morphism f : (D, l, r) → (C, πl , πr ). By the
definition of morphisms in CA×B , f is the unique morphism f : D → C such that
πl ◦ f = l and πr ◦ f = r.
Conversely, suppose that we have a product C ∈ C0 of A and B with morphisms
πl : C → A and πr : C → B. This gives an object (C, πl , πr ) ∈ CA×B 0 . We claim
that this is a terminal object. Indeed, given any object (D, l, r) ∈ CA×B 0 , since C
is a product in C, we have a unique morphism f : D → C such that πl ◦ f = l and
πr ◦ f = r. Therefore, f is a unique morphism in CA×B ((D, l, r), (C, πl , πr )). Since
this holds for any (D, l, r) ∈ CA×B 0 , (C, πl , πr ) is a terminal object in CA×B , which
concludes the proof.

65
Solution 254 (Exercise 98). Let C be a category with a choice of product (A ×
B, πl , πr ) for any two objects A, B ∈ C0 . Take objects A, B, C, D ∈ C0 and morphisms
f : A → C and g : B → D.
πl πr
A A×B B
f ◦πl g◦πr g
f h

C C×D D
πl′ πr′

We have the products (A × B, πl , πr ) and (C × D, πl′ , πr′ ). We have morphisms


f ◦ πl : A × B → C and g ◦ πr : A × B → D. By the universal property of the product
C × D, there exists a (unique) morphism h : A × B → C × D that makes the diagram
commute. This is the morphism we are looking for.
Solution 255 (Exercise 99). Let C be a category with a choice of product (A ×
B, πl , πr ) for any two objects A, B ∈ C0 . Let A, B ∈ C0 be objects.

A×B
πr πl

B g f A

πl′ πr′
B×A

We have the products (A× B, πl , πr ) and (B × A, πl′ , πr′ ). By the universal properties
of the products A × B and B × A, we get morphisms f : A × B → B × A and
g : B × A → A × B, which make the diagram commute.
By the universal property of the product A × B, there exists a unique morphism
h : A × B → A × B such that πl ◦ h = πl and πr ◦ h = πr . Since IdA×B satisfies this,
we have h = A × B. We also have the morphism g ◦ f : A × B → A × B. We have

πr ◦ g ◦ f = πl′ ◦ f = πr

and in the same way, we have πl ◦ g ◦ f = πl . Therefore, g ◦ f = h = IdA×B . In the


same way, we have f ◦ g = IdB×A . Therefore, we conclude that f is the isomorphism
we are looking for, with inverse g.
Solution 256 (Exercise 180). Let F : C → C be an endofunctor and let (µF , in) be an
initial algebra. By definition, LinM is the unique morphism µF → µF that makes the
following diagram commute
in
F (µF ) µF
F LinM LinM

in
F (µF ) µF

66
Since F (IdµF ) = IdF (µF ) , the morphism IdµF satisfies this property, and therefore
LinM = IdµF .
Solution 257 (Exercise 184). Let F : C → C be an endofunctor and let (µF , in) be
an initial algebra. Given F -algebras (C, φ) and (D, ψ) and f ∈ C(C, D), we have the
following commutative diagrams:
in in
F µF µF F µF µF
F (LφM) LφM F (LψM) LψM
φ ψ
FC C FD D
Now, suppose that f ◦ φ = ψ ◦ F (f ).
By definition, LψM is the unique morphism from µF to D such that

LψM ◦ in = ψ ◦ F (LψM).

Therefore, to show that LψM = f ◦ LφM, it suffices to show that

(f ◦ LφM) ◦ in = ψ ◦ F (f ◦ LφM).

And indeed, we have

f ◦ LφM ◦ in = f ◦ φ ◦ F (LφM)
= ψ ◦ F (f ) ◦ F (LφM)
= ψ ◦ F (f ◦ LφM).

Therefore, LψM = f ◦ LφM.


Solution 258 (Exercise 186). Let C be a category with an initial object ⊥. Let
F : C → C be the identity endofunctor.
Note that (⊥, Id⊥ ) is an F -algebra since Id⊥ : ⊥ → ⊥ and ⊥ = F (⊥). Now, to
show that it is initial, suppose we have another F -algebra (X ∈ C0 , f : F X → X).
By initiality of ⊥ in C, we have a unique morphism g ∈ C(⊥, X). To show that g is a
F -algebra morphism, we have to show that the following diagram commutes:
Id⊥
⊥ = F (⊥) ⊥
g=F (g) g

f
X = F (X) X

Because ⊥ is initial, there exists exactly one morphism from ⊥ to X. Therefore,


g = f ◦ g and g is an F -algebra morphism. It is also unique, because ⊥ is initial in C.
Therefore, (⊥, Id⊥ ) is an initial F -algebra.
Solution 259 (Exercise 194). Let F : C → C → C be a bifunctor such that for any
object A ∈ C, the initial algebra (µFA , inA ) for the functor induced by

FA : C → C : X 7→ F (A, X),

67
exists.
We define a functor G : C → C by G(A) = µFA . For A, B ∈ C0 , we have an initial FA -
algebra (µFA , inA : FA (µFA ) → µFA ) and an initial FB -algebra (µFB , inB : FB (µFB ) →
µFB ). Now, for all f ∈ C(A, B), we have by the bifunctoriality of F , a morphism

F ( , µFB )(f ) : FA (µFB ) = F (A, µFB ) → F (B, µFB ) = FB (µFB ).

Then (µFB , inB ◦ F ( , µFB )(f ) : FA (µFB ) → µFB ) is an FA -algebra, so by the initiality
of µFA , we have a unique morphism f ′ : µFA → µFB such that

inB ◦ F ( , µFB )(f ) ◦ FA (f ′ ) = f ′ ◦ inA

and we set G(f ) = f ′ .


We now check that G is a functor. To show that, we need to show that for all A ∈ C0 ,
G(IdA ) = IdµFA and for all f ∈ C(A, B) and g ∈ C(B, C), G(g ◦ f ) = G(g) ◦ G(f ).
For the first property, given an object A ∈ C0 , G(IdA ) : µFA → µFA is the unique
morphism such that

inA ◦ F ( , µFA )(IdA ) ◦ FA (G(IdA )) = G(IdA ) ◦ inA .

Hence, to show that G(IdA ) = IdµFA holds, it suffices to show

inA ◦ F ( , µFA )(IdA ) ◦ FA (IdµFA ) = IdµFA ◦ inA .

This indeed follows by the following computation:

inA ◦ F ( , µFA )(IdA ) ◦ FA (IdµFA ) = inA ◦ IdFA (µFA ) ◦ IdFA (µFA )


= inA
= IdµFA ◦ inA ,

For the second property, given objects A, B, C ∈ C0 , and f : C(A, B) and g : C(B, C),
we have that
inB ◦ F ( , µFB )(f ) ◦ FA (G(f )) = G(f ) ◦ inA
and
inC ◦ F ( , µFC )(g) ◦ FB (G(g)) = G(g) ◦ inB ,
and we know that G(g ◦ f ) : µFA → µFC is the unique morphism such that

inC ◦ F ( , µFC )(g ◦ f ) ◦ FA (G(g ◦ f )) = G(g ◦ f ) ◦ inA .

Note that F is a bifunctor, and therefore, the following diagram commutes:


F ( ,µFB )(f )
F (A, µFB ) F (B, µFB )
F (A, )(G(g)) F (B, )(G(g))
F ( ,µFC )(f )
F (A, µFC ) F (B, µFC )

68
Then we have the following equality:

inC ◦ F ( , µFC )(g ◦ f ) ◦ FA (G(g) ◦ G(f ))


=inC ◦ F ( , µFC )(g) ◦ F ( , µFC )(f ) ◦ FA (G(g)) ◦ FA (G(f ))
=inC ◦ F ( , µFC )(g) ◦ FB (G(g)) ◦ F ( , µFB )(f ) ◦ FA (G(f ))
=G(g) ◦ inB ◦ F ( , µFB )(f ) ◦ FA (G(f ))
=G(g) ◦ G(f ) ◦ inA .

Therefore, G(g ◦ f ) = G(g) ◦ G(f ).


Solution 260 (Exercise 206). Let F : Set → Set be the functor induced by X 7→ 1+X
with 1 = {⋆}. We claim that (Nc , f ) is a terminal coalgebra for this functor, with
Nc = N + {∞} and f : N + {∞} → 1 + N + {∞} given by

0 7→ ⋆
s(n) 7→ n
∞ 7→ ∞

We need to show that for all F -coalgebras (X, g), there exists a unique F -coalgebra
morphism ϕ : (X, g) → (Nc , f ). To this end, take an arbitrary F -coalgebra (X, g).
We first show existence. Borrowing some notation from monads, given the morphism
g : X → F X, we write g ∗ for the induced morphism g ∗ : F X → F X and we write
(g ∗ )n = g ∗ ◦ g ∗ ◦ · · · ◦ g ∗ . We define ϕ : X → Nc as follows: For x ∈ X, if for some
n ∈ N, (g ∗ )n (x) ∈ X and (g ∗ )s(n) (x) = ⋆, we set ϕ(x) = n. Else, we set ϕ(x) = ∞.
We need to show that the following diagram commutes:
g
X 1+X
ϕ Id1 +ϕ
f
N + {∞} 1 + N + {∞}

To that end, take x ∈ X. Suppose that (Id1 + ϕ)(g(x)) = ⋆. Then g 1 (x) = ⋆,


so ϕ(x) = 0 and f (ϕ(x)) = ⋆. Suppose that (Id1 + ϕ)(g(x)) = ∞. Then (by the
definition of ϕ) for all n ∈ N, (g ∗ )s(n) = (x)(g ∗ )n (g(x)) ∈ X, so ϕ(x) = ∞ and
f (ϕ(x)) = ∞. Lastly, suppose that (Id1 + ϕ)(g(x)) = n. Then (by the definition of
ϕ), (g ∗ )s(n) (x) = (g ∗ )n (g(x)) ∈ X and (g ∗ )s(s(n)) (x) = (g ∗ )s(n) (g(x)) = ⋆. By the
definition of ϕ, we then have ϕ(x) = s(n). Then f (ϕ(x)) = n and we conclude that
the diagram commutes and ϕ is a F -coalgebra morphism.
For uniqueness, suppose that we also have a morphism ψ : X → Nc that makes the
diagram commute.
Suppose that for some x ∈ X, g(x) = ⋆. Then, to make the diagram commute,
we must have f (ψ(x)) = (Id1 + ψ)(⋆) = ⋆, so by the definition of f , we must have
ψ(x) = 0.
By induction on n, we will show that for all x ∈ X, if (g ∗ )n (x) ∈ X and (g ∗ )s(n) = ⋆,
we have ψ(x) = n (which equals ϕ(x)). Since we just showed the case for n = 0, we

69
will now show the induction step: suppose that it holds for some n. Take x ∈ X.
If (g ∗ )n (g(x)) = (g ∗ )s(n) (x) ∈ X and (g ∗ )s(n) (g(x)) = (g ∗ )s(s(n)) (x) = ⋆, we have
ψ(g(x)) = n. Then we have f (ψ(x)) = (Id1 +ψ)(g(x)) = n. Therefore, f (ψ(x)) = s(n),
which proves the induction step.
Now, take x ∈ X and suppose that for all n ∈ N, (g ∗ )n (x) ∈ X. If ψ(x) = n for some
n, then (since the diagram commutes), we have ψ(g(x)) = f (ψ(x)) = f (n) = n − 1.
Repeating this n times, we have (Id1 + ψ)((g ∗ )n (x)) = 0. We take x′ = (g ∗ )n (x) ∈ X.
We have ψ(x′ ) = 0 and f (x′ ) = ⋆. However, g(x′ ) ∈ X, so (Id1 + ϕ)(g(x′ )) 6= ⋆ and the
diagram does not commute. Therefore, we cannot have ψ(x) ∈ N, so ψ(x) = ∞ = ϕ(x).
Therefore, ψ = ϕ and we conclude that ϕ is unique, so (Nc , f ) is a terminal F -
coalgebra.
Solution 261 (Exercise 208). We wish to define h, t : N → N such that the following
diagram commutes:
hh,ti
N N×N
nats Id×nats

Stream(N) N × Stream(N)
hhead,taili

This means:

head ◦ nats = h (14)


tail ◦ nats = nats ◦ t (15)

By definition of nats, Eq. (14) means


∀n : N : n = head(nats(n)) = h(n),

and Eq. (15) means


∀n : nats(n + 1) = tail(nats(n)) = nats(t(n)).

Hence, we define (as candidates)

h = IdN , t = succ.
By construction, we have that Eq. (14) and Eq. (15) indeed holds for h := IdN and
t := succ, which shows that the sought function nats : N → Stream(N) is the unique
solution of the equation system

head ◦ nats = Id
tail ◦ nats = nats ◦ succ
and thus can be defined as the anamorphism JhId, succiK.
Solution 262 (Exercise 209). We wish to define h : Stream(A) × Stream(B) → A × B
and t : Stream(A) × Stream(B) → Stream(A) × Stream(B) such that the following
diagram commutes:

70
hh,ti
Stream(A) × Stream(B) A × B × Stream(A) × Stream(B)
zip Id×zip

Stream(A × B) Stream(A × B)
hhead,taili

This means:

head ◦ zip = h (16)


tail ◦ zip = zip ◦ t (17)

By definition of zip, Eq. (16) means

∀as : Stream(A), bs : Stream(B) : (head(as), head(bs)) = head(zip(as, bs)) = h(as, bs),

and Eq. (17) means

∀as : Stream(A), bs : Stream(B) : zip(tail(as), tail(bs)) = tail(zip(as, bs)) = zip(t(as, bs)).

Hence, we define (as candidates)

h = head × head, t = tail × tail.

By construction, we have that Eq. (16) and Eq. (17) indeed holds for h := head × head
and t := tail × tail,
which shows that the sought function zip : Stream(A) × Stream(B) → Stream(A × B)
is the unique solution to the equation system

head ◦ zip = head × head


tail ◦ zip = zip ◦ (tail × tail)

This function can, therefore, be defined as Jhhead × head, tail × tailiK.

A. Forgetful and free functors


A lot of (mathematical) structures are defined as some other kind of mathematical
structure, but where extra structure is added. An example of this is the following:
Recall that a monoid is a set M together with a binary operation m : M → M → M
which is associative and such that there is an identity element e (see Definition 19).
In particular, any monoid has an underlying set and any morphism of monoids has
an underlying function (between those sets). So forgetting the binary operation and
identity element defines a functor from Monoid to Set which is called a forgetful
functor :
Example 263. The forgetful functor from Monoid to Set is the functor specified
by the following data:

71
• The function on objects is given by

Monoid0 → Set0 : (M, m, e) 7→ M.

• The function on objects is given by

Monoid((M1 , m1 , e1 ), (M2 , m2 , e2 )) → Set(M1 , M2 ) : f 7→ f.

Notice that if one defines a category whose objects are sets M together with an
associative binary operation m : M → M → M , then one could analoguously also
define a forgetful functor from Monoid to this category by only forgetting the neutral
element.
Lemma 264. The forgetful functor from Monoid to Set satisfies the properties of a
functor.
Proof. We clearly have that everything is well-defined since the codomain is Set.
That the identity morphism is preserved holds by definition because the identity mor-
phism of (M, m, e) (in Monoid) is given by the identity function and the identity
morphism of M (in Set) is also given by the identity function.
That the composition of morphisms is preserved also holds by definition because the
composition of morphisms (in Monoid) is given by the composition of the underlying
functions which is also the composition in Set.
The forgetful functor F orget from Monoid to Set forgets the algebraic structure
of a monoid and since there are multiple monoid structures on the same set (given
an example of this), hence we do not have that there exists some functor G : Set →
Monoid such that F orget · G is the identity on Monoid. However, to each set, one
can define a monoid which satisfies an important property (this is Proposition 268).
The associated monoid is called the free monoid :
Example 265. Let X be a set. The free monoid generated by X, denoted by
F ree(X), is specified by the following data:
• The underlying set consists of all finite sequences/strings of elements in X (in-
cluding the empty sequence).
• The multiplication is defined by concatenating the sequences, i.e.

m ((x1 , · · · , xn ), (y1 , · · · , ym )) := (x1 , · · · , xn , y1 , · · · , ym ).

• The identity element is given by the empty sequence.


Example 266. The free functor from Set to Monoid is specified by the following
data:
• The function on objects is given by

Set0 → Monoid0 : X 7→ F ree(X).

72
• The function on morphisms is given as follows: A morphism f ∈ Set(X, Y ) (i.e.
a function) is mapped to the monoidal morphism which is given by pointwise
application of f , i.e.

F ree(f )(x1 , · · · , xn ) := (f (x1 ), · · · , f (xn )).

Exercise 267. Show that F ree satisfies the properties of a functor.


For any set X, we have the canonical function

F reeX
! : X → F ree(X) : x 7→ (x).

This function satisfies the property that any function from X to an arbitrary monoid
corresponds with a unique morphism (of monoids) from the free monoid generated by
X to that monoid:
Proposition 268. Let (M, m, e) be a monoid and X be a set. For any morphism f ∈
Set(X, M ) (i.e. a function), there exists a unique morphism φf ∈ Monoid(F ree(X), (M, m, e)),
such that f = F reeX f
! ·φ .

Proof. For elements a, b ∈ M , we denote their multiplication by a × b := m(a, b) (note


that by associativity we have that a1 ×a2 ×· · ·×an ) is well-defined). Let f ∈ Set(X, M )
be a function. Define

φf : F ree(X) → (M, m, e) : (x1 · · · , xn ) 7→ f (x1 ) × · · · × f (xn ),

We have to define separately what happens with the empty sequence. The empty
sequence we map to the identity element e, so in particular we have that the identity
element is preserved under φf , so in order to conclude that φf is a morphism of
monoids, it remains to show that it preserves the binary operation but this is clear by
definition.
That f = F reeX f X
! · φ holds follows immediately by the definition of F ree! and φ ,
f

indeed:
F reeX f
(x) = φf ((x)) = f (x).

! ·φ

So it only remains to show uniqueness. Assume that ψ also satisfies F reeX


! ·ψ = f . The
claim now follows because ψ is a morphism of monoids, indeed: Since ψ is morphism is
monoids, we have that it preserves the multiplication, but the multiplication is given
by concatenation, hence, we have that ψ is uniquely determined by the images of the
sequences of length 1 (and length 0, but this sequence of length 0 should be mapped
under ψ to e). But a sequence of length 1 is of the form (x) = F reeX
! (x). So the claim
indeed follows by the following computation:

ψ((x)) = ψ(F reeX f X f


! (x)) = f (x) = φ (F ree! (x)) = φ ((x)).

73
The following exercise shows that there is a special connection between the forgetful
functor forget : Monoid → Set and the free functor free : Set → Monoid. This
connection expresses that these form a so-called adjoint pair (see Section 6).
Exercise 269. Show that for any set X and monoid (M, m, e), there exist bijections
between the hom-sets:
(M,m,e)
αX : Monoid(F ree(X), (M, m, e)) → Set(X, f orget(M, m, e)).

Hint: use Proposition 268.


Exercise 270. Define a forgetful functor from the category Pos of posets (defined
in Example 14) to Set analoguous to the the forgetful functor from Monoid to Set
(defined in Example 263).
Remark 271. The story about free monoids can not be repeated for posets, i.e.
there is no free poset structure on all sets. But in order to prove this one needs more
machinery.

A.1. Contravariant functors


A variation on functors are contravariant functors. A contravariant functor consists
of a map on objects just like a functor. However, the map on morpisms turns the
morphisms around. We give the formal definition:
Definition 272. Let C and D be categories. A contravariant functor F from C to
D consists of the following data:
• A function
C0 → D0 ,
written as X 7→ F (X).
• For each X, Y ∈ C0 , a function

C(X, Y ) → D(F (Y ), F (X)),

written as f 7→ F (f ).
Moreover, this data should satisfy the following properties:
• (Preserves composition) For f ∈ homC (X, Y ) and g ∈ homC (Y, Z), we have
F (g ◦ f ) = F (f ) ◦ F (g).
• (Preserves identity) For X ∈ C, we have F (IdX ) = IdF (X) .
Exercise 273. Notice that the preservation of composition has now changed, why is
this the case?
An example of a contravariant functor is given by the powerset-functor:

74
Example 274. Recall that the powerset of a set X, denoted by P(X), is the set of
all subsets of X, i.e.
P(X) := {A | A ⊆ X} .
The contravariant powerset-functor5 (on sets), denoted by P, is the functor from
Set to Set defined by the following data:
• The function on objects is given by:
Set0 → Set0 : X 7→ P(X).

• For each X, Y ∈ Set, the function on morphisms is given by


Set(X, Y ) → Set(P(X), P(Y )) : f 7→ f −1 ,
where f −1 given by
f −1 : P(Y ) → P(X) : B 7→ f −1 (B) := {x ∈ X | f (x) ∈ B} .

Exercise 275. Show that P, defined in Example 274 satisfies the properties of a
contravariant functor.

References
[1] Michael Barr and Charles Wells. Category Theory for Computing Science. Orig-
inally published: Prentice-Hall International Series in Computer Science, 1995.
url: http://www.tac.mta.ca/tac/reprints/articles/22/tr22abs.html.
[2] The Catsters. Video lectures on category theory. url: https://www.youtube.com/user/TheCatsters.
[3] Maarten M. Fokkinga. 1990. url: https://maartenfokkinga.github.io/utwente/mmf90.pdf.
[4] HaskellWiki. Hask — HaskellWiki. [Online; accessed 9-April-2022]. 2012. url:
https://wiki.haskell.org/index.php?title=Hask&oldid=52908.
[5] Graham Hutton. “A Tutorial on the Universality and Expressiveness of Fold”. In:
J. Funct. Program. 9.4 (1999), pp. 355–372. url: http://journals.cambridge.org/action/displayAbst
[6] Tom Leinster. Basic Bicategories. https://arxiv.org/abs/math/9810017. 1998.
eprint: math/9810017. url: https://arxiv.org/abs/math/9810017.
[7] Tom Leinster. Basic Category Theory. Available under a Creative Commons
license. url: https://arxiv.org/abs/1612.09375.
[8] Erik Meijer, Maarten M. Fokkinga, and Ross Paterson. “Functional Program-
ming with Bananas, Lenses, Envelopes and Barbed Wire”. In: Functional Pro-
gramming Languages and Computer Architecture, 5th ACM Conference, Cam-
bridge, MA, USA, August 26-30, 1991, Proceedings. Ed. by John Hughes. Vol. 523.
Lecture Notes in Computer Science. Springer, 1991, pp. 124–144. doi: 10.1007/3540543961\_7.
url: https://doi.org/10.1007/3540543961%5C_7.
5 Sincea function is mapped to the inverse-image function, one also calls the powerset-functor, an
inverse image-functor

75
[9] Benjamin Pierce. A taste of category theory for computer scientists. Available for
free. 1988. url: https://kilthub.cmu.edu/articles/journal_contribution/A_taste_of_category_t
[10] Varmo Vene. “Categorical programming with inductive and coinductive types”.
PhD thesis. University of Tartu, 2000.

76

You might also like