โ† back to index

Categories Great and Small

Bartosz Milewski ยท 2014 ยท Category Theory for Programmers, Ch. 3

Prereqs: ๐Ÿž Chapter 1 (Category). 5 min.

Orders and monoids are both categories in disguise. A preorder is a category where each hom-set has at most one morphism. A monoid is a category with exactly one object. Recognizing this collapses two chapters of abstract algebra into two sentences of category theory.

Small categories โ€” finite objects, finite arrows

A small category has a set (not a proper class) of objects. The simplest is the empty category: no objects, no morphisms. One step up: a single object with its identity morphism. Add more objects and arrows, close under composition, keep identities, and you still have a category.

Scheme

Free categories โ€” from graphs to categories

Start with a directed graph. Add an identity arrow at every node. Then close under composition: for every path Aโ†’Bโ†’C, add a composite arrow Aโ†’C. Keep going until no new arrows appear. The result is the free category generated by that graph. One node and one edge already produce infinitely many morphisms: the edge, the edge squared, the edge cubed, forever.

Scheme
d b c a Hasse diagram: a ≤ b ≤ d, a ≤ c ≤ d

Orders โ€” thin categories

An ordered set is a category where the morphism aโ†’b means "a โ‰ค b." Reflexivity gives you identity. Transitivity gives you composition. A category where every hom-set has at most one morphism is called thin. Three flavors:

Scheme
m e a b one object, many endomorphisms

Monoid as a single-object category

A monoid is a set with an associative binary operation and an identity element. String concatenation with the empty string. Addition with zero. Categorically: a monoid is a category with exactly one object. Elements become morphisms, the binary operation becomes composition, and the identity element becomes the identity morphism. The single hom-set M(m, m) is the monoid.

Scheme

Hom-sets

The set of all morphisms from object a to object b is the hom-set C(a, b). For a thin category (preorder), every hom-set is either empty or a singleton. A monoid-as-category has only one hom-set, M(m, m), containing every element of the monoid. A category is locally small if every hom-set is a set (not a proper class).

Scheme

Notation reference

Book Scheme Meaning
C(a, b)(hom-set a b)Set of morphisms from a to b
|C(a, b)| โ‰ค 1(thin-hom a b)Thin category (preorder)
a โ‰ค b(<= a b)Morphism exists in the order-category
m โŠ• n(monoid-compose f g)Monoid operation = composition
emonoid-idIdentity element = identity morphism
Free(G)(free-category-arrows ...)Free category generated by graph G
Neighbors

Milewski chapters

  • ๐Ÿž Chapter 1 โ€” Category: the essence of composition
  • Chapter 4 โ€” Kleisli categories (next)

Related pages

Foundations (Wikipedia)

Translation notes

Milewski covers the Haskell Monoid typeclass (mempty, mappend) and the distinction between point-free and pointwise equality. The examples below translate the same ideas into Scheme and Python. The free monoid on an alphabet is the set of all strings over that alphabet with concatenation; Haskell's String type with (++) is exactly this. Viewing monoids as single-object categories lets them compose with every other categorical construction.

Ready for the real thing? Read the original. Start with "Orders" for thin categories, then "Monoid as Category" for the punchline.