3 ms·
While I am all for stronger type systems, I don't agree that you need it to do sum types. We can already do one half of ADTs (classes ~= product types), I just
by oisdk 7y ago
While I am all for stronger type systems, I don't agree that you need it to do sum types. We can already do one half of ADTs (classes ~= product types), I just want the other half!
In my mind, the syntax would be something like this:
sum_class Tree:
case Leaf:
pass
case Node:
data: Any
left: Tree
right: Tree
def size(tree):
case(Tree) tree of:
Leaf:
return 0
Node(_, left, right):
return 1 + size(left) + size(right)
A combination of data classes and pattern matching.