Interest Ask. If you pull out 'a/'b and replace it with 'b , you will see that the compiler unexpectedly gives you a warning in the - statement.
This tells you that the units to the left and right of the subtraction should be the same, so he limited 'b measure 1 . Why?
x has units 'a
q has units 'b
This tells you that you really need two measurement parameters for your quotient.
type Quotient<[<Measure>]'a, [<Measure>]'b> = |Divisible of int64<'a> |Remaindered of int64<'a> * int64<'b>
This makes sense because any remainder will be in the original units.
let (|/) (x: int64<'a>) (y: int64<'a/'b>) : Quotient<'b,'a> = let q = x / y if q * y = x then Divisible q else Remaindered (q, x - q * y)
source share