Existential types, object-orientation.
Ovidiu Podisor
Ovidiu.Podisor@risc.uni-linz.ac.at
Fri, 07 Nov 1997 14:57:46 +0100
>>>>> On Fri, 7 Nov 1997 13:45:03 +0100, Marco Pil <marcop@cs.kun.nl> wrote:
>> Can you give a simple example of a dynamic type in clean and a
>> spiffy function that uses it to do something otherwise impossible?
MP> Dynamic types are about to be implemented in Clean. Two constructs
MP> have been defined. One for packing a value together with its
MP> type:
MP>
MP> dynamic 5 :: Int
MP> And one for unpacking the 'dynamic' object again, by doing a
MP> run-time pattern match on its type:
MP>
MP> f :: Dynamic -> Int
MP> f (x :: Int) = x
MP> f (x :: Bool) = if x 1 0
MP> f _ = 0
'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.
And I guess that once 'Dynamic' is implemented, exception handling
won't be too far down the road.
Regards,
Ovidiu Podisor