|
|
|
|
|
by valenterry
1312 days ago
|
|
Maybe this is just about terminology. But essentially, when it comes to union types, they behave like sets. The compiler merges them. (A | B) | (A | B) is the same as A | B. But for sum types (even anonymous ones such as tuples) the compiler can't merge them because that would lose information (if the result is from the first A | B or the second one). Instead, you end up with a nested structure. Which one is desired depends on the use-case, but it's definitely different. |
|
But with something like OCaml's polymorphic variants, you could do e.g.
and then switch on the tag (Big or Small) to determine what to do with the values.