Floating point values in F# can have associated
units of measure
, which are typically used to indicate length, volume, mass, and so on. The built-in type float takes an optional unit-of-measure parameter, written in angle brackets, in a similar way that types such as IEnumerable take a
parameter, as in IEnumerable<int>.
By using quantities with units, you enable the compiler to verify that arithmetic relationships have the correct units, which helps prevent programming errors like the one that led to NASA's Mars Climate Orbiter being
in September 1999. This was due to confusion between
and so-called "English
units of measurement
. The accident could have been prevented if the NASA engineers had been able to annotate their program code with units, and then employed static analysis tools or language-level type-checking to detect and fix any unit errors.Andrew Kennedy
is an MSR research scientist who implemented units of measure for F#. What did this involve? How does it work, exactly? What's next? Meet Andrew
and learn all about F#'s latest language feature, units of measure.
Information sources: http://msdn.com