Replies: 5 comments 2 replies
-
If "type-based enums" inherited from |
Beta Was this translation helpful? Give feedback.
-
I'd dive into Union/ADT types in the past. the only problem is that IDE doesn't provide support at all (type-safety works). and finally I'd realize that there is no benefits in almost cases, IMO. using System;
public class Program
{
public abstract class MyUnion
{
public sealed class Left : MyUnion { public int Some; }
public sealed class Right : MyUnion { public Exception Error; }
}
public static void Main()
{
Test(new MyUnion.Left() { Some = 310 });
Test(new MyUnion.Right() { Error = new Exception("From MyUnion.Right") });
}
public static void Test(MyUnion union) // takes MyUnion
{
switch (union)
{
// need to maintain the switch cases manually
// (no error even if it doesn't cover all possible types)
case MyUnion.Left left:
Console.WriteLine(left.Some);
break;
case MyUnion.Right right:
Console.WriteLine(right.Error);
break;
case int p: // type-safety works
Console.WriteLine(p);
break;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
In the case
Can |
Beta Was this translation helpful? Give feedback.
-
I think Another option: I think homogeneous is fine; if you need to mix and match, you can just define your own options as |
Beta Was this translation helpful? Give feedback.
-
Isn't the reverse also true? A union of pre-existing types is just sugar over the union of newly created transparent wrapper types, which don't even have to be types (and can't be types if it's a struct union). And you can't make a struct union of non-types out of a union of pre-existing types. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
https://github.com/dotnet/csharplang/blob/main/meetings/2025/LDM-2025-09-24.md
Agenda
I'm sure no one has opinions on this.
Beta Was this translation helpful? Give feedback.
All reactions