Utilise CLR union types for discriminated unions
CLR has native support for union types; these could provide optimization and performance opportunities for F# discriminated unions.
Zoltan Podlovics commented
A proof of concept explicit structlayout based demo available at:
However, it limited only to blittable types. Combine it with blittable type constraint and you can have stack allocated DU.
Don Syme commented
It would be good to have some mock-up code with performance comparisons for this.
Sam Isaacson commented
When you say "native support for union types" do you mean the usage of attributes <StructLayout( LayoutKind.Explicit )> or something else?
I currently have a need for a DU type that is not heap allocated - this is causing performance problems via the "JIT_new" operation being expensive.
exercitus vir commented
Also interested. Does anyone have more information on native union types in the CLR?
David Taylor-Fuller commented
Would love to know why this wasnt done in the initial implementation.