liveBook · Manning

Category

As explained in Fabulous Adventures in Data Structures and Algorithms

A category is a mathematical structure consisting of objects and composable morphisms between them.

A category is a mathematical structure for studying relationships rather than particular kinds of things. Its objects may be numbers, sets, functions, sequences, programming-language types, or even categories themselves. Its morphisms are directed relationships between objects, written A→B, and compose transitively while including reflexive relationships. Here, “object” means an object of the category, not an object in the object-oriented-programming sense. section 7.1 section 7.4

The same structure supports several useful readings:

  • Treat objects as arbitrary entities and morphisms as arrows expressing relationships between them. section 7.1
  • Treat programming-language types as objects and assignment compatibility as a morphism between types. section 7.4
  • Use category theory to reason about composable operations, abstractions, and design patterns in programming. section 7.0
  • Extend the picture with functors, which map objects between categories while preserving morphisms, either in the same or reversed direction. section 7.4

Types as a category

Imagine a category whose objects are programming-language types. Draw an arrow X→Y when an expression of type X may be assigned to a variable of type Y. These arrows represent assignment compatibility; their transitive structure lets relationships compose across several types. section 7.4

Figure 7.1 A small category with three objects, represented by the nodes, and six morphisms, represented by the arrows

A small node-and-arrow diagram makes the objects, morphisms, and directional structure visible before introducing more elaborate categorical constructions. section 7.1

How Fabulous Adventures in Data Structures and Algorithms covers it

How deep it goes
Defines objects, morphisms, functors, variance, posets, and semilattices, but stops short of deeper category-theoretic development.
Examples
Uses arbitrary objects, directed arrows, programming-language types, assignment compatibility, and small category diagrams.
What it assumes
Assumes familiarity with mathematical functions, programming abstractions, and types while defining categorical terminology from the beginning.
What you can do after
Evaluate programming abstractions as composable relationships and recognize assignment compatibility as a categorical morphism.
How it connects
Connects objects and morphisms with functors, covariance, contravariance, type systems, posetal categories, and semilattices.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fabulous Adventures in Data Structures and Algorithms. The section links point to the parts of the book it draws on.