Hi.
I'm 80% confident in this reply, and 99% confident that someone will
correct me if it's wrong or misleading. :-)
Eileen Head writes:
> Is there an easy way to define a new class, X, of types which is a
> class of some range of types in an existing class Y.
Yes, but only if the existing types can support the functions required
by X, while still supporting the functions required by Y.
Suppose that types T1 and T2 are the existing instances of Y, and that
you want to make T1 an instance of X. Then:
class (Y a) => X a where ...
instance X T1 where ...
There is no easier way than giving an instance declaration for each
type in the range.
> For example can you define a class PosNum in which the type in the
> class are positive Ints, positive Integers, positive Floats and
> positive Doubles?
In this case, it is impossible to make Integer an instance of PosNum,
while still supporting the (-) function required by Num.
Haskell supports inheritance in the sense of "Every data type in class
X is also in class Y (with the programmer providing the proof via
instance declarations)", but not in the sense of "Every value in data
type A is also in data type B". Distinct data types are disjoint,
except for _|_ which is common to all data types.
I hope that helps.
Regards,
Tom