John Meacham  <[EMAIL PROTECTED]>  writes on 4 Mar 2000 

> [..]
> It is VERY useful to allow reuseability of code in ways the original 
> author did not anticipate. 
> for an example from algebra imagine you are given a class Num a 
> which basically represents a field and you need a Group class and 
> would like to reuse the standard operators in Num as well as have all
> types (Num a) automatically work as Groups. With supertyping you can 
> without modifying or accessing the original code at all. you simply 
> declare the following:
>
> (ex. in psuedo-haskell)
>
> class Num a <= Group a where
>       (+) :: a -> a -> a 
>       negate :: a -> a
>
> note the <=, this decares the new class Group from which the 
> existing Num is derived.
> this would create the new class Group and add it to the class 
> inheritance tree above Num, note that the operations in Group must 
> be a subset of what is currently contained in Num, the effect is 
> the exact same as if Num had derived from Group in the first place. 
> [..]


Having the program             class B a where f :: a -> a
                                               g :: a -> Bool,
you can replace it with the program
                               class A a        where f :: a -> a
                               class A a => B a where g :: a -> Bool
and thus, introduce the needed class A.
This is not possible when  B  is of Prelude, or the source program 
with  B  is not given.
Is this the motive for introducing `<=' ?
If yes, then how easily this can be supported?
Probably, the existing implementations put the class declarations 
into the interface modules. And it remains to observe 
                              class B a <= A a where f :: a -> Bool

and replace in the interface the class B with the two new classes
A a  and  A a => B a. 
There remain some details. For example, any instance of old B causes
the instance declaration for A, the latter should, probably, be 
considered as implicit ...
But in principle, will this do?

------------------
Sergey Mechveliani
[EMAIL PROTECTED]









Reply via email to