| >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. 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. |
A sum type is the same thing as a tagged union, a variant record, or a discriminated union (https://en.wikipedia.org/wiki/Tagged_union).