|
|
|
|
|
by bPspGiJT8Y
999 days ago
|
|
> They are to enums what tuple types are to structs. But this is just a generic sum type? data Sum a b = L a | R b
infixr 5 type Sum as ⊕
type E₂ a b z = a ⊕ b ⊕ z
type E₃ a b c z = a ⊕ b ⊕ c ⊕ z
-- and so on…
Here, `Eₙ` represents a sum type with at least `n` members indexed by their position, and `z` represents any type so that it's possible to keep extending the number of positions via further nesting. When you're done you set it to a type with no members: type E₃AndNoMore a b c = a ⊕ b ⊕ c ⊕ Void
I don't know Rust so I can't claim if it allows it, but I'm almost certain it does. |
|
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.