3 ms·
They added record classes (amd record structs) a year or two ago. Discriminated unions are one of the top requested features and they keep hinting that they mi
by HideousKojima 5y ago
They added record classes (amd record structs) a year or two ago. Discriminated unions are one of the top requested features and they keep hinting that they might make it into the next version but it keeps getting pushed back.
- zamalek 5y agoThey want to implement discriminated unions on the heap. I'm excited for the code clarity, but it falls very short of the performance concern raised by an ancestor comment. That's the OOP trade-off. We're also stuck with structured exception handling, so we'll have none of that Rust Result<T>, or Go tuple, goodness.
- phillipcarter 5y agoC# has tuples that are stack allocated
- Smaug123 5y agoF# allows you to put DUs on the stack, with `[<Stack>]`, for what it's worth.
- Smaug123 5y ago(By this I meant `[<Struct>]`, of course.)
- DeathArrow 5y ago>They want to implement discriminated unions on the heap. I'm excited for the code clarity, but it falls very short of the performance concern raised by an ancestor comment. That's the OOP trade-off. That isn't also the case with Haskell, OCaml and F#? IMO, if you care about performance you go procedural and watch how your data is aligned and how many allocations you do. Functional programming kind of requires to use immutable data structures, so you end up making copies and that will impact performance. I don't think you can have both highly performant and expressive code.