Like type-theoretic unions, this will do merging if you instantiate a generic union with the same arguments.
However, direct initialization of such a type (maybe? not sure?) will go through an overload resolution error.
Switching cannot distinguish between cases because there are no separate tags.
Unlike type-theoretic unions, type equality seems to be nominal, not structural. (Could not find definitive wording about this -- inferring from examples)
AFAICT, this doesn't naturally allow for layout optimizations
I don't think there's anything preventing you from performing side effects in the functions related to pattern matching (so reordering would require purity analysis).
I couldn't find anything related to exhaustiveness checking when it comes to arbitrary pattern nesting.
Wow, IMHO that is a really ugly way (boxing) to add something that could kind-of almost pass as being unionish types. It's almost like they sat down to figure out how to change the type system, with the one constraint being that they were not allowed to make any changes whatsoever to the type system.
Sorry that this comment isn't glowingly positive, but I'm both surprised by the design decisions (knowing that there are some brilliant people there working on C#) and even more surprised that no one else here is admitting that they threw up a little in their mouth when they looked at this kludge. I'm not trying to be cruel; I am legitimately surprised.
mattgreenrocks | 17 hours ago
Excited for this! Case inexhaustiveness only being a warning feels like a bit of a footgun though.
gcupc | 16 hours ago
That's interesting, and I wonder what the reasoning was. With the OneOf package (mentioned in the article), it's an error as you'd expect.
typesanitizer | 11 hours ago
Responses to some questions that compiler/PL people might have (disclaimer: not a C# expert, just skimmed https://github.com/dotnet/csharplang/blob/main/meetings%2Fworking-groups%2Fdiscriminated-unions%2Funion-proposals-overview.md + proposals linked from there)
cpurdy | 39 minutes ago
Wow, IMHO that is a really ugly way (boxing) to add something that could kind-of almost pass as being unionish types. It's almost like they sat down to figure out how to change the type system, with the one constraint being that they were not allowed to make any changes whatsoever to the type system.
Sorry that this comment isn't glowingly positive, but I'm both surprised by the design decisions (knowing that there are some brilliant people there working on C#) and even more surprised that no one else here is admitting that they threw up a little in their mouth when they looked at this kludge. I'm not trying to be cruel; I am legitimately surprised.