This might be in one of the books on F# floating about, but if it is I never noticed it.
This example is copied from the F# spec
[<Measure>] type kg [<Measure>] type m [<Measure>] type s let gravityOnEarth = 9.81<m/s^2> let heightOfTowerOfPisa = 55.86<m> let speedOfImpact = sqrt(2.0 * gravityOnEarth * heightOfTowerOfPisa)
So what is so exciting about this? It’s not that you have set units on the first two values, it’s that F# works out the units of the last calculation:
val speedOfImpact : float<m/s> = 33.10548595
How cool is that?
And it checks the units in calculations – so you can’t add a length to a weight if the values have suitable units… YO!