
25 Sep
2010
25 Sep
'10
12:21 p.m.
On Sat, Sep 25, 2010 at 02:34:16AM +0200, Daniel Fischer wrote:
ratPow :: Integral a => Rational -> a -> Rational ratPow _ e | e < 0 = error "Negative exponent" ratPow _ 0 = 1 :% 1 ratPow r 1 = r ratPow (0:%y) _ = 0 :% 1 ratPow (x:%1) e = (x^e) :% 1 ratPow (x:%y) e = (x^e) :% (y^e)
Are you deliberately only doing this for Rational, rather than (Ratio t) in general, to avoid differences in behaviour of Integral types? If it was generalised, then we'd presumably want to use % for the final result, so that (2^16 / 3) ^ 2 :: Ratio Int32 is (0 % 1) rather than (0 % 9). Thanks Ian