Comment by cobbal
4 hours ago
Null doesn't. `union(Int?, String?)` will only have 1 type of null, unlike a proper discriminated union.
4 hours ago
Null doesn't. `union(Int?, String?)` will only have 1 type of null, unlike a proper discriminated union.
The C# unions as described are discriminated unions.
The fact that they flatten a union of optional types into an optional union of the corresponding non-optional types is indeed a weird feature, which I do not like, because I think that a union must preserve the structural hierarchy of the united types, e.g. a union of unions must be different from a union of all types included in the component unions, and the same for a union of optional types, where an optional type is equivalent with a union between the void/null type and the non-optional type, but this C# behavior still does not make the C# unions anything else but discriminated unions, even if with a peculiar feature.