I'm trying to write a unit of measure converter. I have defined two units of measure, KWh and MWh & am trying to write a function to convert between the two that will pattern match on the numeric type. so I could have a float, decimal, int of KWh to convert to MWh. I'm not able to figure out how to correctly branch on type when I don't have a obj type.
Ideas?
[<Measure>]
type KWh
[<Measure>]
type MWh
// want to do this, but can't because x is not x:obj,
// its something like x:float<KWh>
let toMWh x =
match x with
| :? float<KWh> -> x * (1.0<MWh>/1000.0<KWh>)
| :? int<KWh> -> // ...
// above code not valid f#