- 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.
In practice, 0 × A ≅ A × 0 ≅ A for the temptation is too great to divide by zero and I don't know of a single programming language that doesn't succumb.
In the sense that all sorts of operations are in practice divergent for some values of the domain, yeah. But in languages with explicit uninhabited types, the normal rules of algebra apply to those. For example, in Rust which finally got its canonical "never" type stabilized, `(i32, !)` is uninhabited and `Result<i32, !>` is always `Ok(_)` and the compiler knows it.
In a strict language (or with a strict pair in a lazy language), you normally won’t be able to (integer) divide by zero while computing a value, then go on to ignore that, pack that erroneous value into a pair, and extract the other, valid value from it and go on with your life.
Similarly, if your program has hung while computing one half of a pair then (except in lazy languages) it will have hung while computing the pair as a whole as well.
(Haskell’s type algebra is indeed somewhat subtler.)
Natural number, natural logarithm, natural units, natural frequency. I'm not a fan of the term, though it's better than the worst offenders, "normal" and "regular"
> In the normal extension K/Q, every normal subgroup of the regular representation acts on a normal scheme that is regular in codimension one, whose normal bundle — orthonormal to the regular surface at each regular value — carries a normal operator whose spectrum follows a normal distribution over a space that is at once regular and normal, all indexed by a regular cardinal.
Yeah not those, those are legacy, we don’t speak about them :) The “natural” here is that of “natural isomorphism” and more generally the category-theoretic “natural transformation”, which is the one that is virtually always meant when people that the two things are “naturally” identified and the like.
That’s what they mean for example when they say that a finite-dimensional vector space is naturally isomorphic to its double dual, but while it’s also isomorphic to its ordinary dual, it’s not naturally so. Of course, in an introductory course they’ll just say the latter is dependent on an arbitrary choice of basis; but personally I find it quite beautiful that the notion “independent of arbitrary choices” is even formalizable, let alone in such generality as to span from vector spaces to programming languages.
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.
In theory
> 0 × A ≅ A × 0 ≅ 0.
In practice, 0 × A ≅ A × 0 ≅ A for the temptation is too great to divide by zero and I don't know of a single programming language that doesn't succumb.
In the sense that all sorts of operations are in practice divergent for some values of the domain, yeah. But in languages with explicit uninhabited types, the normal rules of algebra apply to those. For example, in Rust which finally got its canonical "never" type stabilized, `(i32, !)` is uninhabited and `Result<i32, !>` is always `Ok(_)` and the compiler knows it.
You’re only right for lazy pairs, I think.
In a strict language (or with a strict pair in a lazy language), you normally won’t be able to (integer) divide by zero while computing a value, then go on to ignore that, pack that erroneous value into a pair, and extract the other, valid value from it and go on with your life.
Similarly, if your program has hung while computing one half of a pair then (except in lazy languages) it will have hung while computing the pair as a whole as well.
(Haskell’s type algebra is indeed somewhat subtler.)
Natural number, natural logarithm, natural units, natural frequency. I'm not a fan of the term, though it's better than the worst offenders, "normal" and "regular"
> In the normal extension K/Q, every normal subgroup of the regular representation acts on a normal scheme that is regular in codimension one, whose normal bundle — orthonormal to the regular surface at each regular value — carries a normal operator whose spectrum follows a normal distribution over a space that is at once regular and normal, all indexed by a regular cardinal.
Yeah not those, those are legacy, we don’t speak about them :) The “natural” here is that of “natural isomorphism” and more generally the category-theoretic “natural transformation”, which is the one that is virtually always meant when people that the two things are “naturally” identified and the like.
That’s what they mean for example when they say that a finite-dimensional vector space is naturally isomorphic to its double dual, but while it’s also isomorphic to its ordinary dual, it’s not naturally so. Of course, in an introductory course they’ll just say the latter is dependent on an arbitrary choice of basis; but personally I find it quite beautiful that the notion “independent of arbitrary choices” is even formalizable, let alone in such generality as to span from vector spaces to programming languages.
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
This is fun. His array example `Σ len: usize . Array(Int, len)` is the list polynomial functor (1 + X + X² + ...) applied to ints.
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: