Proposal: Better power for Rational

Isaac Dupree ml at isaac.cedarswampstudios.org
Sat Sep 25 11:11:58 EDT 2010


On 09/25/10 09:36, Daniel Fischer wrote:
> [ratPow :: (Integral b, Integral a) => Ratio b -> a -> Ratio b
> ratPow ...]
> ratPow (x:%y) e = reduce2 (x^e) (y^e)
>
> reduce2 = (%)
> {-# RULES
> "reduce2/Rational"  reduce2 = (:%) :: Integer ->  Integer ->  Rational
>    #-}

Be careful!  To fire that RULE you need to inline or partially 
specialize ratPow. (re partially specialize, I don't remember if GHC 
allows specializing to a polymorphic type like Integral a => Rational -> 
a -> Rational)

Anyway this goes rather beyond the proposal.

-Isaac


More information about the Libraries mailing list