← Wed, Nov 25 digest

The algebra of dependent types (2025)

read article ↗ hn thread ↗

The author explains why dependent type theory uses big-sigma and big-pi notation by mapping type structures to the number of their possible inhabitants.

read it It offers a refreshingly clear, intuition-building mapping from type theory notation to basic arithmetic and combinatorics.

summary

The post breaks down algebraic data types by counting their possible inhabitants, treating unit types as 1, sums as additions, and products as multiplications. It then extends this counting logic to dependent pairs and dependent functions, showing why these notations emerge from sums of alternative sizes and exponential lookup tables. Commenters expand on polynomial functors, the Curry-Howard correspondence, and practical applications in languages like Rust.

key points

  1. Algebraic data types can be understood by counting their inhabitants, where unit types equal 1, sum types equal addition, and product types equal multiplication.
  2. Dependent pairs act as generalized sums where the size of the second element depends on the value of the first.
  3. Dependent functions represent exponential types or lookup tables where the return type varies based on the passed argument.

who should read it

Functional programmers, type theorists, and software engineers curious about the mathematical foundations of type systems.

discussion warm

consensus

Commenters enthusiastically build on the article, exploring polynomial functors, the Curry-Howard correspondence mapping to predicate logic, and real-world handling of uninhabited types in languages like Rust.

best comment by Sharlin ↗

I find it particularly pleasing how a list can be defined as either:

1) a tagged union of homogeneous tuples of every possible size, ie. (1 + X + X² + ...), or

2) the inductive form, favored in FP: either the empty list or the first element and another list, ie. 1 + X * L

and how it’s easy to show that the two definitions are equivalent:

L = 1 + X + X² + ... // factor out X = 1 + X (1 + X + X² + ...) // note that the (...) is the definition of L = 1 + X * L

It demonstrates how polynomial functors formally connect algebraic type notation to recursive list definitions.

Generated by an LLM from the article and thread. Check the sources before relying on it.