I would like to define a Measure type
[<Measure>] type kB
that converts to the number of bytes when explicitly cast to an int:
(int)7<kB> // would result 1024kB - explicit would be fine
Since there is no way to add an explicit conversion operator to a type like in C#, I am stuck. Anyone has an idea? Even better would be an implicit conversion, so that when a function requires numbers of bytes, it can be called like
Allocate(7<kB>) // implicit would be superfine
Special conversion functions do not appeal - writing a kB function is trivial but not as nice:
let kB(n) = 1024 * n
kB(7)
7 |> kB
A conversion function that does the same with units is not cool either
7<kB> |> convertToByte