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

Ross Paterson <[email protected]>
Newsgroups gmane.comp.lang.haskell.hugs.bugs
Message-ID <[email protected]>
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.
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.