Union types in C# 15
devblogs.microsoft.com
Union types in C# 15
1–10 of 215 posts
Re: Union types in C# 15
#2Re: Union types in C# 15
#3I haven't read this in detail but I expect it to be the same kind of sealed type that many other languages have. It doesn't cover ad-hoc unions (on the fly from existing types) that are possible in F# (and not many non-FP languages with TypeScript being the most notable that does).
Are you sure? This is a feature of OCaml but not F# IIUIR
Edit: https://github.com/fsharp/fslang-suggestions/issues/538
Re: Union types in C# 15
#4I haven't read this in detail but I expect it to be the same kind of sealed type that many other languages have. It doesn't cover ad-hoc unions (on the fly from existing types) that are possible in F# (and not many non-FP languages with TypeScript being the most notable that does).
> unions enable designs that traditional hierarchies can’t express, composing any combination of existing types into a single, compiler-verified contract.
Re: Union types in C# 15
#5Re: Union types in C# 15
#6It's very disappointing that they aren't supporting Rust-style discriminated unions.
Re: Union types in C# 15
#7I haven't read this in detail but I expect it to be the same kind of sealed type that many other languages have. It doesn't cover ad-hoc unions (on the fly from existing types) that are possible in F# (and not many non-FP languages with TypeScript being the most notable that does).
Third paragraph from the top: > unions enable designs that traditional hierarchies can’t express, composing any combination of existing types into a single, compiler-verified contract.
To me that "compiler-verified" maps to "sealed", not "on the fly". Probably.
Their example is:
public union Pet(Cat, Dog, Bird);
Pet pet = new Cat("Whiskers");
- the union type is declared upfront, as is usually the case in c#. And the types that it contains are a fixed set in that declaration. Meaning "sealed" ?
Re: Union types in C# 15
#8It's very disappointing that they aren't supporting Rust-style discriminated unions.
In the article, the example with the switch works because it switches on the class of the instance.
Re: Union types in C# 15
#9Earlier quoted context omitted.
Third paragraph from the top: > unions enable designs that traditional hierarchies can’t express, composing any combination of existing types into a single, compiler-verified contract.
It's very unclear which you mean by that. To me that "compiler-verified" maps to "sealed", not "on the fly". Probably. Their example is: public union Pet(Cat, Dog, Bird); Pet pet = new Cat("Whiskers"); - the union type is declared upfront, as is usually the case in c#. And the types that it contains are a fixed set in that declaration. Meaning "sealed" ?
Re: Union types in C# 15
#10Earlier quoted context omitted.
It's very unclear which you mean by that. To me that "compiler-verified" maps to "sealed", not "on the fly". Probably. Their example is: public union Pet(Cat, Dog, Bird); Pet pet = new Cat("Whiskers"); - the union type is declared upfront, as is usually the case in c#. And the types that it contains are a fixed set in that declaration. Meaning "sealed" ?
OK then, what is the opposite of this, the adhoc union?