January 2018
Beginner to intermediate
312 pages
7h 22m
English
For numeric values, another way of documenting the requirements while ensuring type-safety is to use units of measure. With a units of measure approach, numeric values are annotated with a custom “measure.” For example, we might define some units of measure for kg (kilogram) and m (meter) like this:
| | [<Measure>] |
| | type kg |
| | |
| | [<Measure>] |
| | type m |
And then we annotate some values with those units of measure like this:
| | let fiveKilos = 5.0<kg> |
| | let fiveMeters = 5.0<m> |
|
|
You don’t need to define measure types for all the SI units. They are available in the Microsoft.FSharp.Data.UnitSystems.SI namespace. |
Once this is done, ...
Read now
Unlock full access