# Units of Measure

Floating point and signed values can have length, volume, mass, etc.

This helps the compiler ensure types have the correct units. Used for compile-time checking only so no run-time penalty.

New units can be defined as follows:

 ``` 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: ``` ``````[] type cm [] type ml = cm^3 // Defined in terms of the previous definition [] type miles [] type hour [] type g [] type kg let length = 1.0f printfn "%0.2f" length 55.0 55.0f //single-precision float let gramsToKilos (x: float) = x / 1000.0 let grams = 3452.0 printfn "gramsToKilos %0.2f %0.3f" grams (gramsToKilos grams) ``````

## Generic Units

 ```1: 2: 3: 4: 5: 6: 7: ``` ``````[] type m // meters [] type s // seconds let sumUnits (x: float<'u>) (y: float<'u>) = x + y let result1 = sumUnits 3.1 2.7 // `let result2 = sumUnits 3.1 2.7` // Compile Error: Unit type mismatch ``````

## Aggregate Types with Generic Units

Define a vector type with generic units

 ```1: ``` ``````type vector3D<[] 'u> = {x: float<'u>; y: float<'u>; z: float<'u>} ``````

Create 2 vectors with different units

 ```1: 2: ``` ``````let xvec: vector3D = {x = 0.0; y = 0.0; z = 0.0} let v1vec: vector3D = {x = 0.0; y = 0.0; z = 0.0} ``````

## Conversions

 ```1: ``` ``````let x = float length // Create unitless float from length with units ``````

For interoperability there are also explicit functions

 ```1: ``` ``````let height: float = LanguagePrimitives.FloatWithMeasure x ``````