I am having trouble with F# Units of Measure when defining an operator that has a parameter with a generic unit of measure defined in terms of the generic unit of measure from another parameter. For example:
type Quotient<[<Measure>]'b> =
| Divisible of int64<'b>
| Remaindered of int64<'b> * int64<'b>
let (|/) (x: int64<'a>) (y: int64<'a/'b>) =
let q = x / y
if q * y = x then Divisible q else Remaindered (q, x - (q * y))
Here, y
is defined in <'a/'b>
, where <'a>
is the unit of x
. I am expecting the type of (|/)
to be int64<'a> -> int64<'a/'b> -> Quotient<'b>
, however the compiler is telling me the type is x:int64<'b> -> y:int64 -> Quotient<'b>
.
I want to use this for type conversions where decimal numbers are not possible. My goal was to create operators for working with Quotients instead of putting the logic to compute the remainder in every type conversion. Is it possible to achieve this goal, or should I go about my type conversions a different way?