I found it unexpected that toNum floors the number before converting it to Num a. This is neither documented nor (IMO) something most users would expect to happen.
λ> toUnit @Second $ ms 999
999/1000s
λ> toNum @Second @Rational $ toUnit @Second $ ms 999
0 % 1
AFAICT, there is no way to convert Time unit to an arbitraryNum a => a without flooring the ratio first.
So, I propose we deprecate toNum (and eventually delete it) and split it into floorRat (which already exists) and toFractional:
add toFractional to support properly converting to Double, Float, etc:
We could losslessly convert Time unit -> Ratio Natural -> Ratio Integer
and then use fromRational :: Fractional a => Ratio Integer -> a
to convert to integral types, we already have floorRat:
floorRat has the right constraint to prevent surprises like the ones I described above (Integral instead of Num) and a name that better describes what it does.
I found it unexpected that
toNum
floors the number before converting it toNum a
. This is neither documented nor (IMO) something most users would expect to happen.This can lead to surprising results:
AFAICT, there is no way to convert
Time unit
to an arbitraryNum a => a
without flooring the ratio first.So, I propose we deprecate
toNum
(and eventually delete it) and split it intofloorRat
(which already exists) andtoFractional
:toFractional
to support properly converting to Double, Float, etc:Time unit
->Ratio Natural
->Ratio Integer
fromRational :: Fractional a => Ratio Integer -> a
floorRat
:floorRat
has the right constraint to prevent surprises like the ones I described above (Integral
instead ofNum
) and a name that better describes what it does.