3 ms·
These are all synonyms, even in type theory: > In computer science, a tagged union, also called a variant, variant record, choice type, discriminated union, di
by searealist 2y ago
These are all synonyms, even in type theory:
> In computer science, a tagged union, also called a variant, variant record, choice type, discriminated union, disjoint union, sum type, or coproduct, is a data structure used to hold a value that could take on several different, but fixed, types. [1]
C++ class inheritance is not a sum type for a couple reasons:
- It does not allow you to discriminate on the type.
- You can add RTTI, which allows you to discriminate, but then it is not a fixed set of types.
Obviously, Rust does sum types better than C++, but that is really irrelevant.
[1] https://en.wikipedia.org/wiki/Tagged_union https://en.wikipedia.org/wiki/Tagged_union
- tialaramex 2y agoIt's true, in the "Encyclopedia anyone can edit" you will find that quote.
- searealist 2y agoToday you learned what a sum type is.
- tialaramex 2y agoI already knew what a sum type is. Fortunately I discovered Rust, which actually has proper sum types rather than trying to make do with a tagged union and a whole lot of squinting.