Re[2]: Existential types, object-orientation.

RSeagraves@mindscape.com RSeagraves@mindscape.com
Fri, 7 Nov 1997 12:25:06 -0800


Please remove me from the Clean mailing list.
    Thanks
        Reggie
        rseagraves@mindscape.com


___________________________________________________________________________
____
Subject: Re: Existential types, object-orientation.
From:    Marco Pil <marcop@cs.kun.nl> at MINDSCAPE
Date:    11/7/97  3:26 PM




Ovidiu Podisor wrote:
 > 'Dynamic' could be thus regarded as type with an unbounded number of
 > contructors (one for every 'real' type).
 >
 > This resembles the treatement of the 'Exception' type in ML, which is
 > again a type with an unbounded number of constructors *and* allowing
 > pattern matching.
 >
 > The way this is implemented in the Standard ML compiler is that the
 > tag is not a (small) integer but the memory address of a string
 > (the exception name).
 >
 > I wonder how the 'Dynamic' construct is implemented in Clean.
 >

The dynamic construct in Clean is implemented by a tuple of an value
and an encoded version of its type.
The types are not coded as integers, for two reasons:
1. There is more than just pattern matching: actually a full-blown
   type unification algorithm is executed at run-time. For this the
   type code has to have some structure.
   One can write the following functions:
    dynamicApply :: Dynamic Dynamic -> Dynamic
    dynamicApply (f :: a -> b) (x :: a) = dynamic (f x) :: b
    dynamicApply  _             _       = dynamic "Type Error" :: String
    dynI  = dynamic I :: (A.a: a -> a)
    dyn37 = dynamic 37 :: Int
   so that  'dynamicApply dynI dyn37'  results in  'dynamic 37 :: Int'.
2. Dynamic values are designed to persist beyond the borders of one
   application. And, as different programs can define their own
   datatypes (sometimes using the same name for different types),
   is necessary to encode the entire definition of all datatypes.

Regards,
Marco Pil