Existential types, object-orientation.

Nick Kallen phantom@earthlink.net
Thu, 6 Nov 1997 15:17:05 -0800


>>Existential types are a spiffy feature for psuedo-object orientation as is
>>clearly seen in the Clean book in the OO Drawing program chapter. I have a
>>few questions related to object-orientation as seen in some of the more
>>modern mixed languages like Java and Oberon:
>>    Can one can use inheritence or class polymorphism with Existential
types
>>in Clean? If not, are these concepts even compatible?
>
>I don't understand this question. Can you be more precise?


Sure.
    In an OO language, when you inherit from class Drawable you -extend-
rather than replace it. And, rather than there being only one state
variable, there can be many. So, if Drawable already has some field
position, a Rectangle that inherits from Drawable could merely extend this
by adding a new field Size. Let me put this in psuedo-code to explain what I
mean.

class Drawable
    {    position: (Int, Int)
    , ...
    }

class Rectangle (Drawable)    // the "(Drawable)" means it inherits from
Drawable
    {    size: (Int, Int)
    , ...
    }

Now, you can think of the actual type of Rectangle as:
    {    position: (Int, Int)
    ,    size: (Int, Int)
    , ...
    }

Thus, Rectangle inherits from, or -extends- Drawable. I don't think this can
be done with existential types because you can't add fields to the record.
This is what I mean.

>Dynamic types are currently being implemented in the new Clean compiler.
>Any static type T can be converted to a dynamic type. Via pattern matching
>one can inspect a dynamic type and unify with other dynamic types.


Can you give a simple example of a dynamic type in clean and a spiffy
function that uses it to do something otherwise impossible?

>You can have a look in the Object I/O library which makes use of
existential types.

Will the Object I/O library ultimately use dynamic types?