Replies: 5 comments 32 replies
-
I am really happy that you have decided to go ahead with class unions before finalizing the whole design. Speaking of struct union challenges, how does F# work around the problem of large structs? As far as I know, it performs no optimizations to reduce the size of the union.
I thought the bigger problem was that generic types couldn't have explicit locations. Runtime doesn't get confused, it flat out refuses to load a struct union where you try to pack all kinds into |
Beta Was this translation helpful? Give feedback.
-
The types can by sorted by some type id when constructing ValueUnion type. Or am I missing something? |
Beta Was this translation helpful? Give feedback.
-
This is almost too amazing for words. Unions finally looking like they are coming to the C# language. Bloody brilliant. 🥳 🍾 🎉 |
Beta Was this translation helpful? Give feedback.
-
How much overlap is there between discriminated unions and type unions? In these discussions on GitHub we often talk about them together but as far as I see it they're completely separate features. Would C# get them both? Are unions preferred over DUs (imagined as closed hierarchies with some declaration sugar)? Completely separate point: how will type unions work with casts, especially regarding generics? Assuming that this is not legal: var x = (Cat or Dog)y; where does the error occur in this?: T Cast<T>(object val) => (T)val;
var x = Cast<Cat or Dog>(y); |
Beta Was this translation helpful? Give feedback.
-
By "class union" I presume this means something akin to F# discriminated union, which is a closed hierarchy of nested types declared kind of like an enum of records, right? type Shape =
| Rectangle of width : float * length : float
| Circle of radius : float
| Prism of width : float * float * height : float 🍝 public union Shape {
record Rectangle(float width, float length);
record Circle(float radius);
record Prism((float, float) width, float height);
} While I'm sure it's the easiest form to solve for I am also curious as to the use cases. It's a departure from how domain types are defined today, and presumably could not be adapted to existing models. I also don't believe that it would serve the |
Beta Was this translation helpful? Give feedback.
-
https://github.com/dotnet/csharplang/blob/main/meetings/2025/LDM-2025-01-13.md
Agenda
Beta Was this translation helpful? Give feedback.
All reactions