Original-Via: uk.ac.nsf; Tue, 1 Oct 91 21:42:55 BST
Original-Sender: [EMAIL PROTECTED]
I tried to insert the Enum class (page 30) into the diagram
of numeric classes (figure 7, page 55), but got confused.
Every standard type in class Real is individually declared
to be an instance of Enum, using the same functions
(numericEnumFrom and numericEnumFromThen, page 90).
Yet, Real is technically not a subclass of Enum.
The declaration of Real (page 57 or 86) is
class (Num a, Ord a) => Real a where
toRational :: a -> Rational
so I wonder why it isn't
class (Num a, Ord a, Enum a) => Real a where
toRational :: a -> Rational
enumFrom = numericEnumFrom
enumFromThen = numericEnumFromThen
I guess the answer is that class operations must either be defined
at the topmost class (in this case Enum), or for each individual
type, but not at an "intermediate" class (like Real).
In "The Next Stage" section, page vii, it says that in the
future, a class declaration may include default methods for
operations of its superclasses, which _override_ the superclass's
default methods.
But in the Enum/Real case, Enum has no default methods for
enumFrom and enumFromThen, so no overriding is necessary.
It would be interesting to see an explanation of the technical problems
of having default definitions in an "intermediate" class declaration.
-- Mikael R.