by searealist · 2y ago · 0 comments
I don't think I've ever seen an analogy contribute to a discussion, and yours is no exception.
sum Expr { Int; Add(Int,Int) }
VS
class Expr { }
class Add extends Expr { Expr left; Expr right; }
std:variant<int,std::string> sum_type_instance = 5;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)
struct Add {} std::variant<Add, int> Expr;
OR
class Expr {} class Add : Expr {}