3 ms·
"In type-system theory this is called a "Sum Type" because we can define all possible representations" It is indeed a sum type, but I don't think that is why (
by dllthomas 12y ago
"In type-system theory this is called a "Sum Type" because we can define all possible representations"
It is indeed a sum type, but I don't think that is why (or true of all sum types, or less true of product types). It sounds like they are conflating "enum"?
As an example of a product type for whom we can define every possible representation: ((),()) has precisely one representation.
As an exampe of a sum type for whom there are infinite representations: (Either String Integer)
My understanding has it that it is called a sum type because 1) for finite types the number of representations is the sum of the number of representations under each tag, and 2) it behaves more generally like a sum (a^x * a^y = a^(x+y) is an equality in arithmetic, (x -> a, y -> a) is isomorphic to ((Either x y) -> a) in programming).
- mazelife 12y agoThat's a good point. A sum type/disjoint union (by my understanding) means the type is in the union of subsets and that the subsets are pairwise disjoint, but it doesn't say that the subsets have to be finite. Since this post is really aimed at Haskell beginners, I was trying to avoid going down the rabbit hole as regards type system or set theory and I might have oversimplified in the process.