Enum class
Malcolm Wallace
Malcolm.Wallace@cs.york.ac.uk
Wed, 24 Oct 2001 11:52:57 +0100
I just thought I should add the results for hbc and nhc98 to this
enumeration of woes, to further illustrate the difficulties.
> i :: Int
> i = 0x7fffffff
>
> i_plus_1 = i+1
> -- ghc : -2147483648
> -- hugs: -2147483648
-- nhc98: -2147483648
-- hbc: -2147483648
> i_succ = succ i
> -- ghc : *** Exception: Prelude.Enum.succ{Int}: tried to take `succ' of maxBound
> -- hugs: -2147483648
-- nhc98: -2147483648
-- hbc: -2147483648
> j :: Int
> j = 0x80000000
> -- ghc : -2147483648
> -- hugs: Program error: {primIntegerToInt 2147483648}
-- nhc98: -2147483648 (+ warning: decimal constant is so large that it is unsigned)
-- hbc: -2147483648
> k :: Int
> k = 0x100000000
> -- ghc : 0
> -- hugs: Program error: {primIntegerToInt 4294967296}
-- nhc98: 0
-- hbc: 0
> i':: Integer
> i'= 0x7fffffff
> i_plus_1' = i+1
> -- ghc : 2147483648
> -- hugs: 2147483648
-- nhc98: 2147483648
-- hbc: 2147483648
> i_succ' = succ i'
> -- ghc : 2147483648
> -- hugs: -2147483648
-- nhc98: -2147483648
-- hbc: -2147483648
> I think Hugs is wrong. Integer shouldn't wrap.
(Actually, ghc is `wrong': hbc, hugs and nhc98 match the Report's
specification here: succ = toEnum . (+1) . fromEnum
This is confirmed by the description of the semantics in section 3.10.)
> succ 1.45
> -- hugs: 2.0
> -- ghci: 2.45
-- nhc98: 2.0000000000000000
-- hbc: 2.0
> succ 1.99
> -- hugs: 2.0
> -- ghci: 2.99
-- nhc98: 2.0000000000000000
-- hbc: 2.0
> succ 1.99999
> -- hugs: 2.0
> -- ghci: 2.99999
-- nhc98: 2.0000000000000000
-- hbc: 2.0
> succ (-0.2)
> -- hugs: 1.0
> -- ghci: 0.8
-- nhc98: 1.0000000000000000
-- hbc: 1.0
> succ (-0.99999)
> -- hugs: 1.0
> -- ghci: 9.99999999995449e-6
-- nhc98: 1.0000000000000000
-- hbc: 1.0
> succ (-1.1)
> -- hugs: 0.0
> -- ghci: -0.10000000000000009
-- nhc98: 0.0000000000000000
-- hbc: 0.0
Ghc does not follow the Report here either.
> [1.0..2.5]
> -- hugs: [1.0,2.0,3.0]
> -- ghci: [1.0,2.0,3.0]
-- nhc98: [1.0000000000000000,2.0000000000000000]
-- hbc: [1.0,2.0,3.0]
> [1.1..2.5]
> -- hugs: [1.1,2.1]
> -- ghci: [1.1,2.1]
-- nhc98: [1.0000000000000000,2.0000000000000000]
-- hbc: [1.1,2.1]
> [1.1..3.0]
> -- hugs: [1.1,2.1,3.1]
> -- ghci: [1.1,2.1,3.1]
-- nhc98: [1.0000000000000000,2.0000000000000000,3.0000000000000000]
-- hbc: [1.1,2.1,3.1]
nhc98 is wrong for all the Double arithmetic sequences.
Regards,
Malcolm