Unions merged into dotnet 11 preview 3

10 points by martinald


Struggling to find a link that lobsters allows. But unions have been merged into dotnet 11:

Julien Couvreur (@jcouv) We merged an early C# 15 preview feature into .NET 11 preview 3: unions.

Adds union declarations (union Pet(Cat, Dog, Bird) { ... }) and union types (attributed with [Union]). They can be treated by pattern matching/switch expressions as a closed set for exhaustiveness.

maxdeviant

I was excited for this up until I got to this part:

The proposed unions in C# are unions of types and not "discriminated" or "tagged". "Discriminated unions" can be expressed in terms of "type unions" by using fresh type declarations as case types. Alternatively they can be implemented as a closed hierarchy, which is another, related, upcoming C# feature focused on exhaustiveness.

Unless I’m missing something, it feels like another instance of “borrow ideas from F#, but make them worse”.

martinald

FWIW I just tested it out (on the nightly builds, it'll be available in preview 3 in ~a month and it works brilliantly. Really excited for this!

m_a_r_k

I am very excited to be able to use unions.

Though maybe it will just make me further want to use haskell instead.