~/ ~/documents ~/recommended-reading ~/software ~/pictures github (opens in new tab)

Geometry of Abstract Structure

Often described as β€œthe mathematics of mathematics”, category theory is simply the study of connections, structures, and processes. Traditional set theory looks inside an object to see what elements it contains. Category theory stands back and looks at the outsideβ€”how objects relate to each other through arrows.

Formally, a category π’ž\mathcal{C} is defined as a tuple (Ob(π’ž),Hom(π’ž),∘,id)(\text{Ob}(\mathcal{C}), \text{Hom}(\mathcal{C}), \circ, \text{id}) consisting of:

subject to three foundational axioms:

  1. Closure under Composition: βˆ€f∈Hom(A,B),g∈Hom(B,C)⟹(g∘f)∈Hom(A,C)\forall f \in \text{Hom}(A, B), g \in \text{Hom}(B, C) \implies (g \circ f) \in \text{Hom}(A, C)

  2. Identity Laws: For every object A∈Ob(π’ž)A \in \text{Ob}(\mathcal{C}), there exists a unique identity morphism idA∈Hom(A,A)\text{id}_A \in \text{Hom}(A, A) such that for any f:Aβ†’Bf : A \to B: f∘idA=f=idB∘ff \circ \text{id}_A = f = \text{id}_B \circ f

  3. Associativity of Composition: For all f:Aβ†’Bf : A \to B, g:Bβ†’Cg : B \to C, and h:Cβ†’Dh : C \to D: (h∘g)∘f=h∘(g∘f)(h \circ g) \circ f = h \circ (g \circ f)

We gain an intuitive grasp of these abstract rules by replacing mathematical symbols with geometric shapes (β—‹,β–«,β–³\bigcirc, \square, \triangle) as our objects and shape transformations as our arrows.

In this shape universe, we ignore the internal pixels or vertices of an object and focus entirely on directed, structure-preserving transformations: a circle transforming into a square (f:β—‹β†’β–«f : \bigcirc \to \square), or a square transforming into a triangle (g:β–«β†’β–³g : \square \to \triangle).

For these shapes and arrows to form a valid category, the categorical axioms must hold strictly. When we have a transformation f:β—‹β†’β–«f : \bigcirc \to \square and another transformation g:β–«β†’β–³g : \square \to \triangle, there must exist a composite arrow g∘f:β—‹β†’β–³g \circ f : \bigcirc \to \triangle representing the direct route from circle to triangle. Furthermore, every shape AA possesses an identity morphism idA\text{id}_Aβ€”a β€œdo nothing” transformationβ€”leaving the shape invariant. Whether we group successive transformations as (h∘g)∘f(h \circ g) \circ f or h∘(g∘f)h \circ (g \circ f), associativity guarantees that the final resulting shape is identical.

By constraining or expanding the structure of our shape universe, specific mathematical concepts emerge naturally. Consider a category containing only one object—a single, universal shape SS—accompanied by many arrows. This single-object category is a Monoid. The arrows represent self-transformations (S→SS \to S) such as rotating ninety degrees, scaling by two, or inverting colors, while composition chains these actions and the identity arrow acts as do_nothing. In software engineering, familiar abstractions like string concatenation or integer addition with zero mirror this exact single-object categorical structure.

Conversely, if we consider a category where between any two shapes AA and BB there is at most one arrow, we obtain a Preorder or partial order (such as ≀\le). An arrow exists from shape AA to shape BB if and only if Size(A)≀Size(B)\text{Size}(A) \le \text{Size}(B). Composition becomes transitivity: if Small≀Medium\text{Small} \le \text{Medium} and Medium≀Large\text{Medium} \le \text{Large}, then an arrow guarantees Small≀Large\text{Small} \le \text{Large}. Identity satisfies reflexivity, as every shape is at least as large as itself.

Moving beyond single categories, a Functor F:π’žβ†’π’ŸF : \mathcal{C} \to \mathcal{D} acts as a structure-preserving mapping from one category of shapes to another. It translates every object AA in π’ž\mathcal{C} into an object F(A)F(A) in π’Ÿ\mathcal{D}, and maps every arrow f:Aβ†’Bf : A \to B in π’ž\mathcal{C} into an arrow F(f):F(A)β†’F(B)F(f) : F(A) \to F(B) in π’Ÿ\mathcal{D}, preserving identity (F(idA)=idF(A)F(\text{id}_A) = \text{id}_{F(A)}) and composition (F(g∘f)=F(g)∘F(f)F(g \circ f) = F(g) \circ F(f)). Imagine Category π’ž\mathcal{C} containing simple plain shapes and Category π’Ÿ\mathcal{D} containing framed container shapes; a functor FF maps plain shapes to container shapes without tearing down the underlying relationships between them. In programming, container types like List<T>, Maybe<T>, or Result<T> are functors whose map function lifts shape transformations f:Aβ†’Bf : A \to B into F(f):F(A)β†’F(B)F(f) : F(A) \to F(B).

When we need to map between two different functors operating over the same categories, we arrive at a Natural Transformation Ξ±:Fβ‡’G\alpha : F \Rightarrow G. A natural transformation transforms shape containers without disturbing the underlying shape transformations. For every shape AA, Ξ±A\alpha_A supplies an arrow F(A)β†’G(A)F(A) \to G(A) satisfying the commutative diagram property: G(f)∘αA=Ξ±B∘F(f)G(f) \circ \alpha_A = \alpha_B \circ F(f). If FF produces filled shapes (FilledShape\text{FilledShape}) and GG produces outlined shapes (OutlinedShape\text{OutlinedShape}), Ξ±\alpha converts filled shapes into outlined shapes. Transforming a filled circle into a filled square and then outlining it yields the exact same outlined square as outlining the filled circle first and then transforming it to an outlined square. Polymorphic functions like headOption : List<A> -> Option<A> or flatten : List<List<A>> -> List<A> are real-world natural transformations.

Category theory also reconstructs familiar algebraic data types purely through universal shape interactions. A Product (AΓ—BA \times B) pairs two objects into a single compound shape (ShapeA,ShapeB)(\text{Shape}_A, \text{Shape}_B) with projection arrows (fst, snd) to extract each component, corresponding to records or structs.

A Coproduct (A+BA + B) defines a choice between shapes (Either ShapeA ShapeB) with injection arrows (inl,inr\text{inl}, \text{inr}), mirroring sum types, enums, or tagged unions.

Viewed through geometric shapes and transformations, category theory demonstrates that software architecture is not an arbitrary collection of patternsβ€”it is geometry in abstract space.

Category Theory Concept Shape Visualization Programming Equivalent
Object
Discrete Shape Entities (β—‹,β–«,β–³\bigcirc, \square, \triangle)
Type (e.g.Β Int, String, User)
Morphism
Transformation Arrow (f:β—‹β†’β–«f : \bigcirc \to \square)
Pure Function (A -> B)
Category
Shapes, Composite Arrows & Identity
Type System & Functions
Monoid
Self-transformations on 1 Shape
Accumulator / Monoid (concat, +)
Preorder
Order Relation Arrows (Size(A)≀Size(B)\text{Size}(A) \le \text{Size}(B))
Comparable Types / Partial Order
Functor
Lifting Shapes & Arrows across Categories
Generic Container with map (List, Maybe)
Natural Transformation
Morphing Container Functors (α:F⇒G\alpha : F \Rightarrow G)
Polymorphic Function (headOption, flatten)
Product
Shape Pair (β—‹,β–«)(\bigcirc, \square) with Projections
Record / Struct / Pair ((A, B))
Coproduct
Choice between Shapes (β—‹βˆ¨β–«\bigcirc \lor \square)
Enum / Union / Sum Type (Either A B)