signum (recip (-1 :% 1)) should not be 1 % 1

Ralf Welter <[email protected]>
Newsgroups gmane.comp.lang.haskell.hugs.bugs
Message-ID <[email protected]>
Hi!

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.

Descriptiion:
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.

Hope this helps - I havn't had the time to check if ghc and other 
implementations suffer from the same issue.

regards,
	ralf welter
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.