O'Haskell OOP Polymorphic Functions
Ashley Yakeley
ashley@semantic.org
Wed, 17 Jan 2001 16:37:01 -0800
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