Re: O'Haskell OOP Polymorphic Functions

At 2001-01-17 16:07, Johan Nordlander wrote:
Ashley Yakeley wrote:
OK, I've figured it out. In this O'Haskell statement,
struct Derived < Base = value :: Int
...Derived is not, in fact, a subtype of Base. Derived and Base are disjoint types, but an implicit map of type "Derived -> Base" has been defined.
-- Ashley Yakeley, Seattle WA
Well, they are actually subtypes, as far as no implicit mapping needs to be defined. But since Derived and Base also are two distinct type constructors, the overloading system treats them as completely unrelated types (which is fine, in general).
All O'Haskell treats them as completely unrelated types. In fact, this O'Haskell...
struct Base = b1 :: Int b2 :: Char
struct Derived < Base = d1 :: Int
...is a kind of syntactic sugar for this Haskell...
data Base = Base (Int,Char) dotb1 (Base (x,_)) = x dotb2 (Base (_,x)) = x
data Derived = Derived (Int,Char,Int) dotd1 (Derived (_,_,x)) = x
implicitMap (Derived (b1,b2,d1)) = Base (b1,b2)
This seems to be stretching the concept of 'subtype'. Sorry if I sound so bitter and disappointed. I was hoping for a Haskell extended with real dynamic subtyping... -- Ashley Yakeley, Seattle WA

Ashley Yakeley wrote:
This seems to be stretching the concept of 'subtype'.
I don't think so, this is the essence of subtyping.
Sorry if I sound so bitter and disappointed. I was hoping for a Haskell extended with real dynamic subtyping...
You seem to want dynamic type tests. This is another feature, and sometimes a useful one. But it requires carrying around types at runtime. You might want to look at existential types; it is a similar feature. -- Lennart
participants (2)
-
Ashley Yakeley
-
Lennart Augustsson