4 ms·
It makes no sense to mention dyanmic_cast or inheritance (clearly referencing virtual functions here) when languages with sum types also have equivalents. It ju
by searealist 2y ago
It makes no sense to mention dyanmic_cast or inheritance (clearly referencing virtual functions here) when languages with sum types also have equivalents. It just shows a misunderstanding of how these features are used.
I don't think I've ever seen an analogy contribute to a discussion, and yours is no exception.
- maattdd 2y agoInheritance (the subtyping part of it) is considered the OOP way to write sum type. sum Expr { Int; Add(Int,Int) } VS class Expr { } class Add extends Expr { Expr left; Expr right; }
- searealist 2y agoThat's not C++.
- maattdd 2y agoAny reader who comment here hopefully has enough knowledge to understand the implied C++. struct Add {} std::variant<Add, int> Expr; OR class Expr {} class Add : Expr {}
- searealist 2y agoI dont think you have ever seriously used c++.
- deleted 2y ago[deleted]
- gpderetta 2y agoThe expression problem enters the room.
- OvbiousError 2y agoYou 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
- OvbiousError 2y agoIndeed. There seems to be quite the lack of understanding what the mentioned concepts actually are.