- There’s also the notation 0 for the empty (never, noreturn) type. In addition to matching the number of members, the notations 0 and 1 make sense also as units (neutral elements) of addition and multiplication respectively: 0 + A ≅ A + 0 ≅ A, 1 × A ≅ A × 1 ≅ A in a natural way[1]; and also 0 × A ≅ A × 0 ≅ 0.
- That a constant dependent sum is a product, and a constant dependent product is an exponential, is (undeniably confusing at first but) just[2] the naïve schoolbook definition that A × B = B added to itself A times and A^B = A multiplied by itself B times.
- That a constant dependent product is a function type is just the naïve definition that a function is a table of its values at each input (a tuple, with elements numbered by the possible inputs). A dependent function ( = dependent product), then, is the same thing but the allowable values in each cell of the table vary depending on the cell.
- That the function type is the exponential type is also part of common set-theory notation. For instance, 2^ℕ is a not-infrequent name for the set in the Cantor theorem (subsets of the naturals).
[1] As in, those are not literally the same type but are one-to-one in a single natural way. The word “natural” here has a surprisingly deep technical meaning but one that corresponds to the colloquial pretty well.
[2] “Just”, “simply”, etc. are as usual terms of art that mean that the statement feels very simple once you get it, and conversely that if it does not feel simple then you haven’t gotten it and should stop and think until it does. That thinking can take substantial time and effort.
show comments
solomonb
This is fun. His array example `Σ len: usize . Array(Int, len)` is the list polynomial functor (1 + X + X² + ...) applied to ints.
Note that in order to understand the above you need to grasp "Type of Types" i.e. Sorts.
The whole Typed Lambda Calculus to Calculus of Constructions (based on dependent types) is very nicely and succinctly explained by Helmut Brandl in his 100-page booklet Typed Lambda Calculus / Calculus of Constructions - https://hbr.github.io/Lambda-Calculus/index.html
A couple of notes:
- There’s also the notation 0 for the empty (never, noreturn) type. In addition to matching the number of members, the notations 0 and 1 make sense also as units (neutral elements) of addition and multiplication respectively: 0 + A ≅ A + 0 ≅ A, 1 × A ≅ A × 1 ≅ A in a natural way[1]; and also 0 × A ≅ A × 0 ≅ 0.
- That a constant dependent sum is a product, and a constant dependent product is an exponential, is (undeniably confusing at first but) just[2] the naïve schoolbook definition that A × B = B added to itself A times and A^B = A multiplied by itself B times.
- That a constant dependent product is a function type is just the naïve definition that a function is a table of its values at each input (a tuple, with elements numbered by the possible inputs). A dependent function ( = dependent product), then, is the same thing but the allowable values in each cell of the table vary depending on the cell.
- That the function type is the exponential type is also part of common set-theory notation. For instance, 2^ℕ is a not-infrequent name for the set in the Cantor theorem (subsets of the naturals).
[1] As in, those are not literally the same type but are one-to-one in a single natural way. The word “natural” here has a surprisingly deep technical meaning but one that corresponds to the colloquial pretty well.
[2] “Just”, “simply”, etc. are as usual terms of art that mean that the statement feels very simple once you get it, and conversely that if it does not feel simple then you haven’t gotten it and should stop and think until it does. That thinking can take substantial time and effort.
This is fun. His array example `Σ len: usize . Array(Int, len)` is the list polynomial functor (1 + X + X² + ...) applied to ints.
I think Dependent Types are easier to understand following Curry-Howard Correspondence (https://en.wikipedia.org/wiki/Curry%E2%80%93Howard_correspon...) where the mapping to Logic is clearly spelled out.
1) Propositional Logic = Simple Types
2) Predicate Logic = Dependent Types (https://en.wikipedia.org/wiki/Dependent_type) where;
2.1) Existential Quantification = Σ-types (aka Dependent Sum/Pair) - https://en.wikipedia.org/wiki/Dependent_type#%CE%A3_type
2.2) Universal Quantification = Π-types (aka Dependent Product/Function) - https://en.wikipedia.org/wiki/Dependent_type#%CE%A0_type
Note that in order to understand the above you need to grasp "Type of Types" i.e. Sorts.
The whole Typed Lambda Calculus to Calculus of Constructions (based on dependent types) is very nicely and succinctly explained by Helmut Brandl in his 100-page booklet Typed Lambda Calculus / Calculus of Constructions - https://hbr.github.io/Lambda-Calculus/index.html