Reading the paper "Type Classes with Functional Dependencies" by Mark P. Jones, I noticed he mentions the "Coerce" class as a way to model the subtyping relation. I have looked at the article there referred, "How to make ad-hoc polymorphism less ad-hoc" by Wadler and Blott. By now, I can't find more references to this idea; it looks very promising for when one wants subtyping in haskell: ********** class Subtype a b where convert :: a -> b instance Subtype a a where convert = id call f x = f (convert x) -- Silly but powerful example instance (Show a) => Subtype a String where convert = show -- Does not type if overlapping instances are allowed -- --instance Functor SList where -- fmap f End = End -- fmap f (a:::as) = (call f a):::(fmap f as) ********** This leads to many compilation problems, one has to use -fallow-undecidable-instances (guess why ^___^), -fallow-overlapping-instances and -fglasgow-exts, and fmap is still not typing but... why has no one cared till now? If someone can give me pointers to articles that shows other problems of this approach, or extends this simple idea, I'll be grateful. Vincenzo
On Fri, 21 Feb 2003 08:05:37 +0100 Nick Name <nick.name@inwind.it> wrote:
-- Does not type if overlapping instances are allowed -- --instance Functor SList where -- fmap f End = End -- fmap f (a:::as) = (call f a):::(fmap f as)
I skipped the declaration of SList, which is the coolest part of the story to my eyes: data SList a = forall b . (Subtype b a) => (:::) b (SList a) | End This is a list holding values of subtypes of a. Vincenzo
On Friday, February 21, 2003, at 06:05 PM, Nick Name wrote:
Reading the paper "Type Classes with Functional Dependencies" by Mark P. Jones, I noticed he mentions the "Coerce" class as a way to model the subtyping relation. I have looked at the article there referred, "How to make ad-hoc polymorphism less ad-hoc" by Wadler and Blott.
By now, I can't find more references to this idea; it looks very promising for when one wants subtyping in haskell:
Have a look at the paper "Object-Oriented Style Overloading for Haskell" by Shields & Peyton-Jones: http://research.microsoft.com/~simonpj/Papers/oo-haskell/index.htm -- % Andre Pang : just.your.average.bounty.hunter
participants (2)
-
Andre Pang -
Nick Name