3 ms·
sum types are are not all that different from subtyping+inheritance, it's simply the other side of the expression problem.
by platz 9y ago
sum types are are not all that different from subtyping+inheritance, it's simply the other side of the expression problem.
- nixpulvis 9y agoOther side?
- platz 9y agohttp://wiki.c2.com/?ExpressionProblem http://wiki.c2.com/?ExpressionProblem > The "expression problem" is a phrase used to describe a dual problem that neither ObjectOrientedProgramming nor FunctionalProgramming fully addresses. "dual problem", meaning you choose ObjectOrientedProgramming or FunctionalProgramming, which neither fully address. neither "side" is able to resolve the ExpressionProblem
- nixpulvis 9y agoInteresting, though I'm not sure I like the notion that it's a two sided coin. I've also never been a fan of the OO vs FP argument.
- yen223 9y agoUnlike subtyping, sum types are bounded - you can't add new variants without modifying the originally-defined type. That's a huge difference in terms of code architecture - it enables things like exhaustive pattern matching, and allows the programmer to enforce stronger invariants in the code.
- rbehrends 9y agoSubtyping can be closed, too (see Scala's sealed classes, for example) and algebraic data types can be open (see OCaml's extensible variants [1] or polymorphic variants [2]). This is simply a distinction between closed and open sum types. [1] https://caml.inria.fr/pub/docs/manual-ocaml/extn.html#s%3Aextensible-variants https://caml.inria.fr/pub/docs/manual-ocaml/extn.html#s%3Aex... [2] http://caml.inria.fr/pub/docs/manual-ocaml-400/manual006.html#toc36 http://caml.inria.fr/pub/docs/manual-ocaml-400/manual006.htm...
- l_dopa 9y agoActually, they're the "other side" of products types, which are sometimes called "records" or "structs". Maybe they're occasionally used to solve the same problem, but inheritance is unrelated. Inheritance is a variety of ad-hoc methods for sharing code with quite different semantics in every language where it's implemented.