|
|
|
|
|
by duped
1001 days ago
|
|
> But this is just a generic sum type? No, it's actually less generic. It's not determined by position but by type. For example `A | B | A` is the same type as `A | B`. This is useful as a shorthand when you don't want/need a new type to represent your problem, similar to tuples. |
|
> This is useful as a shorthand when you don't want/need a new type to represent your problem, similar to tuples.
Yes this is handled perfectly by the generic sum type, you don't need untagged unions for this. Rust used to have Either in its standard library, but they removed it and kept Result only. Semantically they're the same (a ⊕ b) but Result's name implies it has something to do with some "results". Anyways nothing stops you from creating one yourself, or even using Result if you're fine with the weird-sounding name.