| A sum type `T = A | B` means that a value of type `T` can be either of type `A` or of type `B`. Such a type is used to express polymorphism. A product type (from "Cartesian product", i.e tuples) `T = A * B` means that a value of type `T` has a component that is of type `A` and another component that is of type `B`. It is used to aggregate parts into a whole. > Yes, I could go and research functional programming languages and type theory It has absolutely nothing to do with functional programming and touches only upon the barest essentials of type theory (and calling it type theory is already stretching it, because it's just about defining a couple of common computer science concepts). Sum and product types are fundamental computer science vocabulary to such an extent that it's not really possible to have a useful discussion about programming language semantics without them. |
Taking this example (in English / pseudocode):
Define a class Animal.
Define Dog as a subclass of Animal.
Define Cat as a subclass of Animal.
Case 1) Now if we have a variable a1 that can, at runtime, contain (or refer to) either a Dog or an Animal instance.
Case 2) And if we have a variable a2 that can, at runtime, contain (or refer to) either a Dog or a Cat instance.
Referring to your quoted sentences above, would you say that Case 1, Case 2 or both, are about sum types?
Just trying to understand the terminology.