Proposal: Better recip for Ratio a

I propose to change the implementation of recip in the Fractional instance of Ratio a to make it faster. Currently, the instance defines recip (x:%y) = y % x which means that the gcd of numerator and denominator is recalculated, although for all properly generated values, they are known to be coprime. (Invalid vlaues can be obtained via direct use of the constructor or via fromRational cf. http://hackage.haskell.org/trac/ghc/ticket/4335.) Period of discussion: Three weeks, unitl 15th October (because of ICFP). Ticket: http://hackage.haskell.org/trac/ghc/ticket/4336 For Rationals with large numerators and denominators, the proposed implementation recip (0:%_) = error "Ratio.%: zero denominator" recip (x:%y) | x < 0 = negate y :% negate x | otherwise = y :% x gives a huge speedup.
participants (2)
-
Daniel Fischer
-
Felipe Lessa