hn.today

The algebra of dependent types (2025)

dotat.at108 points19 comments
Screenshot of The algebra of dependent types (2025)

The piece explains why dependent type theory uses the symbols Σ and Π by connecting them to familiar algebraic data types and the number of values each type can contain. A unit type has one inhabitant, a Boolean has two, product types combine values in pairs and multiply their possible counts, while sum types offer alternatives and add their counts. These arithmetic interpretations provide a way to understand the notation rather than treating it as arbitrary jargon.

A dependent pair has a second component whose type is determined by the first component’s value. For example, a slice can store a length together with an array whose type records that length. Its possible values can be viewed as alternatives across all lengths, so their counts are added, using a large Σ; when the second type does not depend on the first, this reduces to an ordinary product. A dependent function likewise has a result type that varies with its input. Ordinary functions from A to B can be counted as lookup tables with one B-valued entry for each A, giving B raised to the power A. For dependent functions, the number of possible outputs varies across inputs, and the corresponding count is a product, written with a large Π. The piece also notes that “telescope” names a sequence of dependent bindings and warns that “dependent sum” and “dependent product” can be confusing labels.

Read on dotat.at19 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.