top | item 41157352 (no title) maattdd | 1 year ago Inheritance (the subtyping part of it) is considered the OOP way to write sum type.sum Expr { Int; Add(Int,Int) }VSclass Expr { }class Add extends Expr { Expr left; Expr right; } discuss order hn newest OvbiousError|1 year 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|1 year ago My 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|1 year ago You 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 load replies (1) gpderetta|1 year ago The expression problem enters the room. searealist|1 year ago That's not C++. maattdd|1 year ago Any reader who comment here hopefully has enough knowledge to understand the implied C++.struct Add {} std::variant<Add, int> Expr;ORclass Expr {} class Add : Expr {} load replies (2)
OvbiousError|1 year 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|1 year ago My 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|1 year ago You 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 load replies (1)
maattdd|1 year ago My 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|1 year ago You 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 load replies (1)
searealist|1 year ago That's not C++. maattdd|1 year ago Any reader who comment here hopefully has enough knowledge to understand the implied C++.struct Add {} std::variant<Add, int> Expr;ORclass Expr {} class Add : Expr {} load replies (2)
maattdd|1 year ago Any reader who comment here hopefully has enough knowledge to understand the implied C++.struct Add {} std::variant<Add, int> Expr;ORclass Expr {} class Add : Expr {} load replies (2)
OvbiousError|1 year ago
maattdd|1 year ago
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|1 year ago
https://en.wikipedia.org/wiki/Expression_problem
gpderetta|1 year ago
searealist|1 year ago
maattdd|1 year ago
struct Add {} std::variant<Add, int> Expr;
OR
class Expr {} class Add : Expr {}