5 ms·
Sum types =/= union types. Sum types are also called 'tagged' or 'discriminable' unions because they have some way to discriminate between them. That is, if you
by ImprobableTruth 5y ago
Sum types =/= union types. Sum types are also called 'tagged' or 'discriminable' unions because they have some way to discriminate between them. That is, if you have an element a of type A, a is not part of the sum type A + B because it's missing a tag.
[5,"hello",3] has the type list (int ∪ string), not list (int + string). You can emulate the latter by manually adding a tag, but native support is much preferable.
- joshlemer 5y agoI know the differences between untagged and tagged unions, I'm trying to provide a minimal example without distracting details but sure we can talk about tagged unions. Here is a list of tagged unions, so I once again point out that sum types are "supported" in JSON/ions just as much as any other data type: [ {tag: "a", foo: 1}, {tag: "b", bar: "hi", baz: 2}, {tag: "a", foo: 3}, {tag: "a", foo: 4}, {tag: "a", foo: 5}, {tag: "b", bar: "yo", baz: 6} ]