3 ms·
There are many benefits of sum types: - Their values can be discriminated at runtime (it's depending on the implementation of union types whether that's possib
by choeger 4y ago
There are many benefits of sum types:
- Their values can be discriminated at runtime (it's depending on the implementation of union types whether that's possible. In C a union is just a structure large enough to hold all constituents)
- You can sum the same type (union(Int, Int) simply is Int)
- The tag breaks recursion. You can build recursive sum types because of it, e.g. 'a List = Empty | Cons('a, 'a List)
- earleybird 4y ago> You can sum the same type (union(Int, Int) simply is Int) I'm not sure this is the case. In some cases Union(Int, Int) might be interpreted as a union of Left-Int or Right-Int Then again, my understanding of sum vs union might not be overly precise :-) edit: s/now/not/