
17 Sep
2019
17 Sep
'19
10:53 a.m.
Using the numerator and denominator functions in Data.Ratio adds an extra layer of laziness to functions that have to work with Ratios (especially Rationals). I think it'd be convenient if there were a pattern synonym exported from the safe Data.Ratio: pattern n :% d <- (n GHC.Ratio.:% d) where n :% d = n % d This way, destructuring is as fast as if you were to import GHC.Ratio directly, but it can't be used to create invalid Ratios. The only disadvantage is that using the :% to destructure it requires an Integral constraint on the value, but 99% of the time, the value will be Integer anyway, and even in the remaining 1% you still can't construct a Ratio a without an Integral a constraint in safe code anyway, so it shouldn't matter.