signum (recip (-1 :% 1)) should not be 1 % 1
Ross Paterson
ross@soi.city.ac.uk
Fri, 6 Dec 2002 10:26:59 +0000
On Thu, Dec 05, 2002 at 07:04:34PM +0100, Ralf Welter wrote:
> I think I have found a bug in the hugs prelude:
> Bug: definition of recip in the instance declaration of breaks silent
> assumptions about the internal data in Ratio types.
>
> Description:
> data Integral a => Ratio a = !a :% !a deriving (Eq)
> by deriving Eq a normal form is assumed. Further places do at least
> assume a positive denominator:
>
> >instance Integral a => Num (Ratio a) where
> > ...
> > abs (x :% y) = abs x :% y
> > signum (x :% y) = signum x :% 1
> silently assume the denominator is positive
>
> unforturtunately the definition of recip
> >instance Integral a => Fractional (Ratio a) where
> > ...
> > recip (x:%y) = y :% x
> will break these properties.
> fix: remove the colon on the right hand side of the recip definition.
Thanks for the report and fix -- you're right, this is what the Report
specifies (and what GHC does). It's now fixed in CVS.