Eg: https://sharplab.io/#v2:EYLgZgpghgLgrgJwgZwLQAUEEsC2UECeAwgP...
Eg: https://sharplab.io/#v2:EYLgZgpghgLgrgJwgZwLQAUEEsC2UECeAwgP...
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...
Probably one of my favorite recent-ish additions to the language.
I think they would add it by C# 14 or 15.
Anyone that cares so deeply about them can do the work on a F# assembly.
C# has done great in the industry for the past 23 years without them.
Languages are not used in isolation, great IDE experience, and having mature libraries for every use I can think of, is more valuable than grammar and semantics.
Also a reason why I would rather do FP in C++23 than Haskell, even with all the warts and paper cuts it entails, ecosystem.
Additionally, they add friction to a development stack, now everyone needs to be confortable with two language stacks, and most of the time it isn't really worth it.
The hope and the expectation is that the CLR will gain support for first-class representations of F# concepts to allow for greater interop with C# scenarios, but the CLR's development has always been tied to C#, with other CLR languages like VB.NET and C++/CLI only exerting minor influence on the CLR's design with most of their language-specific idiosyncrasies being handled by library-code and compile-time tricks instead (e.g. VB.NET's "On Error Resume Next" statement is implemented by having the compiler wrap each individual statement in a try/catch instead of having the CLR specifically support it (though in this specific case that's probably a good idea as OnErrorResumeNext is a horrible idea I'm sure we all agree).
Which is kind of ironic given how they usually leave C++/CLI out of the picture, including the cross platform story.
[1] https://devblogs.microsoft.com/dotnet/new-csharp-12-preview-... [2] https://devblogs.microsoft.com/dotnet/new-csharp-12-preview-...
I can manage without DU, have used plenty of languages without them since Caml Light.
I believe I am overlooking something (probably obvious even to me) since i know:
https://learn.microsoft.com/en-us/dotnet/fsharp/language-ref...
is perhaps a misuse of the term in this context.
(I'm guessing you mean more like in Rust, but am not sure.)
(There are multiple proposals tracking the idea. This seems the most comprehensive and "central": https://github.com/dotnet/csharplang/issues/7016)
https://github.com/linkdotnet/Blog.Discussions/discussions/7...
Is is kind of a pain particularly when working across Typescript projects. OneOf is cool, but it DOES NOT work well with null and thus optional parameters.
For now, you can get a reasonable DU via an [external library](https://github.com/mcintyre321/OneOf).
[Nick Chapsas Video on Usage](https://www.youtube.com/watch?v=7z-xjijYfcI).
But in any case I really love this addition to the language but the inability to have multi-line or block expression arms is a constant annoyance for me.
You can even combine these with the new one line record syntax to create a poor man’s discriminated union.
The workaround for that is the same as the workaround for the really lame one line limitation: you need to call a (preferably (static) local) function in the handler portion and then return something like `true` assigned to a discard. Hacks all around!
Eg
_ = foo switch a when … => CaseA(foo), _ => CaseB(foo);
With CaseA and CaseB returning bool in order to call a function depending on the value of foo rather than assign a value.
F# / C# interop ... cool thing, just to clarify.