I am very new to F # and intrigued by the Units of Measure functionality and have a general idea of how it works normally, but I would like to know if it is possible to bind measures to values where we do not know what the measure will be until the code won't fulfill?
The practical example I'm looking at is mandatory floats as currency values, where the unit of measure is inferred from the database search.
Suppose that measures for each currency (USD, EUR, AUD, etc.) are usually announced:
[<Measure>] USD
[<Measure>] EUR
[<Measure>] AUD
...
First you need a way to get the type of measure from the identifier, ideally the name of the measure itself, since the currency code is most likely stored and retrieved as a 3-character string (similar Enum.Parse()).
Then you need a way to bind the float value to the type created in the previous step.
Is this possible, or is there another way to achieve the same result?
source
share