the algebra of dependent types (2025)
The algebra of dependent types, as explored in a recent learning experience, sheds light on the usage of Greek letters Π and Σ in type theory notation. These symbols, typically understood from context, have a more intuitive explanation when connected to algebraic data types.
For instance, the unit type () has only one inhabitant, denoted as (), akin to the number 1. The boolean type, bool, contains two inhabitants, false and true, reminiscent of the number 2. Similarly, pairing or tuple types, such as pairs or records, follow a multiplication rule for the number of possible values, reflecting their algebraic nature.
Dependent pairs, or Σ-types, introduce an additional layer of complexity. Here, the type of the second element hinges on the value of the first. A classic example is a slice, where an array [i64; N] requires its size to be specified, while an IntSlice type knows its size inherently. In type theory, a dependent pair is often written as Σ (i64; N), binding a variable with a type annotation.
The number of potential values in a dependent pair is the sum of possibilities for each case, akin to a summation operation. Conversely, when the second element does not depend on the first, the count of inhabitants reduces to a product type, mirroring the conventional multiplication rule.
The term "telescope" for multi-part dependent tuples or records, derived from AUTOMATH, a pioneering computerized proof assistant, adds further depth to this algebraic approach. The return type of a dependent function, depending on the passed argument, can be viewed as a large lookup table, akin to the product of multiple functions, denoted as BA. Functions, as exponential types, can be counted by considering each as a tuple of possible outputs, or BA.
While terms like "dependent sum" and "dependent product" might seem intuitive, they can be confusing when discussing variants, records, or functions. Thus, the preference for "sum type" persists, despite its limitations.
Rewritten by urgent.news; may contain errors — check the original.
Source: dotat.at