4 ms·
> Why do we call them product types anyway? Answer in the piece is not wrong, but put more intuitively and succinctly: the total number of possible value (inha
by aranchelk 3y ago
> Why do we call them product types anyway?
Answer in the piece is not wrong, but put more intuitively and succinctly: the total number of possible value (inhabitants) in a product type is the product of the quantity of inhabitants of the constituent types.
Replace the “product”s with “sum”s and it works too.
Interestingly, the total number of unique functions (judged only in terms of input and output) from a -> b can be found by exponentiation, (inhabitants of b) ^ (inhabitants of a).
- wscp-dev 3y agoIll add that in, somehow forgot about that golden bit of info
- trenchgun 3y ago>Answer in the piece is not wrong, but put more intuitively and succinctly: the total number of possible value (inhabitants) in a product type is the product of the quantity of inhabitants of the constituent types. More intuitively and succintly: product type is equivalent to a cartesian product of sets
- tubthumper8 3y agoMaps (and lists) are other examples of exponential types. Intuitively this should make sense that these are the same as functions because any pure function could be (theoretically) replaced with a map lookup of pre-computed values. In this context, list is a special map where the keys are integers. Writing it out mathematically, given a List of Bool, the left-hand side is the number of elements and the right-hand side is the total possibilities. - 0 : 1 - 1 : 2 - 2 : 4 - 3 : 8 - 4 : 16 - 5 : 32 and so on