Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiled form of named union fields in v3.1

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.

like image 916
Daniel Avatar asked Oct 22 '22 01:10

Daniel


1 Answers

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#:

enter image description here

In fact, it also uses the name in parameters of the construction functions:

enter image description here

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).

like image 102
Tomas Petricek Avatar answered Oct 25 '22 19:10

Tomas Petricek