Negative literals and the meaning of case -2 of -2 -> True

Simon Peyton-Jones simonpj@microsoft.com
Mon, 27 May 2002 09:28:06 -0700


Fixed.

Simon

| -----Original Message-----
| From: Simon Marlow [mailto:simonmar@microsoft.com]=20
| Sent: 17 May 2002 10:34
| To: Thomas Hallgren; haskell@haskell.org
| Subject: RE: Negative literals and the meaning of case -2 of=20
| -2 -> True
|=20
|=20
|=20
| > To find out how Haskell implementations treat negated
| > literals, I tested=20
| > the following program:
| >=20
| > ------------------------------------------------
| > main =3D print (minusTwo,trueOrFalse)
| >=20
| > minusTwo =3D -2::N
| >=20
| > trueOrFalse =3D
| >     case minusTwo of
| >       -2 -> True
| >       _ -> False
| >=20
| > data N =3D Negate N | FromInteger Integer deriving (Eq,Show)
| >=20
| > instance Num N where
| >   negate =3D Negate
| >   fromInteger =3D FromInteger
| > -------------------------------------------------
| >=20
| > The result is:
| >=20
| >     * ghc 5.02.2: main outputs: (FromInteger (-2),True)
|=20
| GHC has two bugs in this area, one of which has been fixed=20
| recently. The current output is (Negate (FromInteger=20
| 2),False) (i.e. the same as hbc).  We were being a little too=20
| eager to replace 'negate (fromInteger N)' by 'fromInteger=20
| (-N)'.  There is also a bug in the pattern handling, however.
|=20
| Thanks for a nice test case...
|=20
| Cheers,
| 	Simon
|=20
| _______________________________________________
| Haskell mailing list
| Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell
|=20