Publicly exported pattern synonym for Ratios?

Zemyla zemyla at gmail.com
Tue Sep 17 14:53:44 UTC 2019


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20190917/238cbf3c/attachment.html>


More information about the Libraries mailing list