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?
Units: The names of all units start with a lower case letter except, of course, at the beginning of the sentence. There is one exception: in "degree Celsius" (symbol °C) the unit "degree" is lower case but the modifier "Celsius" is capitalized. Thus, body temperature is written as 37 degrees Celsius.
The 7 Base Metric Units These dimensions are measurements of length, mass, time, electric current, temperature, amount of a substance, and luminous intensity. Here are definitions of the seven base units: Length: Meter (m) The meter is the metric unit of length.
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.
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