About "class Coerce a b"
Nick Name
nick.name@inwind.it
Fri, 21 Feb 2003 08:05:37 +0100
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