3 ms·
You should probably look up what a sum type is, it has nothing to do with summations. Your example doesn't contain a sum type. A C++ example: std:variant<i
by OvbiousError 2y ago
You should probably look up what a sum type is, it has nothing to do with summations. Your example doesn't contain a sum type. A C++ example:
std:variant<int,std::string> sum_type_instance = 5;
- maattdd 2y agoMy sum type example is exactly this (but I didn't use C++ std::variant<> syntax to not confuse the reader). The most common example of a sum type is the "Expression problem" - please read some literature before commenting on a topic. (Btw, it's called sum type for a reason: summation. The cardinality of the sum type is the sum of the cardinality of its variants)
- Maxatar 2y agoYou seem to have a very narrow C++ view of what sum types are. Sum types are related to the expression problem, and the given example is the canonical instance of the expression problem. https://en.wikipedia.org/wiki/Expression_problem https://en.wikipedia.org/wiki/Expression_problem
- searealist 2y agoSum types are not “anything that can encode an expression”. They have a precise definition. They are closed and a synonym for a tagged union.
- Maxatar 2y agoPlease use quotes to refer to a statement that someone has actually made. Doing otherwise is an indicator that you are making a strawman argument.
- searealist 2y agoToday you learned what a sum type is. Just admit your ignorance and move on with your life. Maybe bookmark this: https://en.wikipedia.org/wiki/Tagged_union https://en.wikipedia.org/wiki/Tagged_union
- Maxatar 2y agoLooks like you are very easily triggered on this topic. Quite amusing to be honest :)
- tialaramex 2y ago"synonym for a tagged union" Tagged unions are an implementation and one that's often a poor fit for the problem. Sum types are an idea from type theory, rather than an implementation detail. It's very on-brand for C++ to have standardized a poor implementation detail rather than the useful idea. Look at how much hoop jumping was required to make std::optional<T&> work for C++ 26 and then compare how Rust's Option<&T> isn't even special, that's just naturally what happens.
- searealist 2y agoThese 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.