Haskell 98: Enum class
Wed, 24 Oct 2001 16:09:39 +0100
| | (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.)
| Lies, all lies. The default methods do not constitute a specification;
| in this case at least, they only approximate the truth.
But the Report is emphatic that Appendix A _does_ constitute a
specification for the Prelude, and I had always assumed that the
default definitions given there are "safe" for all types, though not
If the default methods are semantically incorrect (for some types)
then they must be changed or removed.
| The Report is (regrettably) silent about what the Integer
| instances for succ and pred should be, but they should definitely simply
| add 1 (resp subtract 1).
Admittedly section 3.10 does not mention succ and pred explicitly,
but it does otherwise confirm the semantics of the current default
definitions, namely that:
"For other discrete Prelude types t that are instances of Enum,
namely ... Integer, the semantics is given by mapping ... to Int
using fromEnum, ... , and then mapping back to t with toEnum."
However I agree that
succ = (+1)
pred = (\x-> x-1)
would make better sense.
> 5. In Appendix A, the Enum class defn, add comments to explain that the
> default methods only work for types whose fromEnum/toEnum range fits
> inside Int.
I would rather have correct default definitions.