pub enum Either<Head, Tail> {
Left(Head),
Right(Tail),
}Expand description
The Either type, a.k.a. σ, is used to represent an anonymous sum type.
Similar to Cons, Either is used to form a sum type
by combining a chain of Either types, and terminated with a Void type.
But unlike product types, a sum type has values that belong to one
of the variants in the list.
Either is also shown as σ, together with Void shown as θ, to improve
the readability of compiler error messages. Through the shortened name, a sum
type would take slightly less space, making it more likely to fit on a single
line for the user to read what the type is.
Either is most often used through the Sum! macro, which accepts a list of
types and turns them into a chain of Either types.
§Example
Given the following sum type definition:
type MyUnion = Sum![u32, String, bool];The following type would be generated:
type MyUnion = Either<u32, Either<String, Either<bool, Void>>>;which would be shown with the shortened representation as:
type MyUnion = σ<u32, σ<String, σ<bool, θ>>>;