7

I'm just starting with F# and am wondering about units of measure:

I understand they are only present at compile time and Reflector confirms this: creating a unit of measure that is not an alias creates a class with MeasureAttribute attribute, but other than that, float<km/h> is represented as plain System.Double. And there are no attributes on the type, constructor parameter or properties.

So far I understand. But when I reference the compiled assembly from another project, it seems to know all about the units of measure, including aliases. How does it get that information? Where in the assembly are they?

svick
  • 236,525
  • 50
  • 385
  • 514

1 Answers1

10

F# stores 'extra type information' in a resource in the compiled assembly, and the F# compiler knows how to read that resource. So whereas a discriminated union is just compiled into, say, a class, and a unit of measure is erased into a double, there's extra F#-specific type info in a resource in the assembly so that when the F# compiler reads it, it can re-construct the extra "F# metadata".

The PowerPack has a metadata reader that lets you access it programmatically.

Brian
  • 117,631
  • 17
  • 236
  • 300