Firstly, is the F# 3.1 spec available online? If so, the answer for this should be easy enough to find.
I'm wondering if the compiled form of discriminated unions with named fields (added in 3.1) will include properties with the names of the fields, instead of the usual Item1
, Item2
, ... properties.
As far as I know, the specification is not available yet, so the only way to tell is to try it. I installed VS 2013 RC, so I thought I could check using this union:
type Expression =
| Add of Left:Expression * Right:Expression
| Constant of number:int
As expected, it does generate named properties, which are nicely useable from C#:
In fact, it also uses the name in parameters of the construction functions:
If you're using them for C# interoperability, then you'll probably want to write the union member names in PascalCase
, because the compiler does not automatically capitalize the name of the property if you use lowercase name (but interestingly, it does use a lowercase name for the parameters).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With