Supertyping Suggestion for Haskell

Pardon if my terminology is a bit off, but this is my first Haskell language suggestion. In any case I thought a feature that might be very useful for Haskell would be the ability to supertype as well as subtype classes. Basically it would allow you too add nodes anywhere in the class inheritance tree rather than just extending the bottom. 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 pseudo-Haskell)

class Num a <= Group a where
	(+) :: a -> a -> a 
	negate :: a -> a

note the <= , this declares 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.

this would take much of the burden of any author writing reusable components to come up with the 'perfect' class inheritance tree. It would also be particularly useful in Haskell since overloading takes place only via classes so a not well thought out class can eat up a lot of the namespace which you would like to reuse for more fine grained components (as in the above example.)

This functionality becomes even more necessary when faced with binary-only libraries and standard language features which cannot be easily rewritten or overridden without great effort.

note that supertyping has been used successfully in Sather (http://gnu.org/software/sather ). Although Sather is an imperative OO language its type systems consists of declarative inheritance of interfaces which are somewhat similar to simple Haskell classes.

let me know what you think... if this functionality already exists or it horribly breaks the soundness of the typesystem then i apologize. It does not seem to adversely affect the typesystem as far as i can tell as it does not really add any new constructs it only generalizes class hierarchy construction... of course, as always, i could just be plain wrong.


Copyright © 1995-2004 John Meacham