Python from Wise Guy's Viewpoint
Neelakantan Krishnaswami
neelk at cs.cmu.edu
Tue Nov 11 15:11:05 EST 2003
In article <boqboc$4p2$1 at f1node01.rhrz.uni-bonn.de>, Pascal Costanza wrote:
> Fergus Henderson wrote:
>
>> Suppose the original ML program defines the following functions
>>
>> foo : int -> int
>> bar : string -> string
>> ...
>>
>> We can add dynamic typing like this:
>>
>> datatype Generic = Int of int
>> | String of string
>> | Atom of string
>> | Cons Generic Generic
>> | Apply Generic Generic
>> | ...
> ^^^
> How many do you need of those, especially when you want to allow that
> type to be extended in the running program?
Two more.
datatype generic = ...
| Class of generic ref
| Object of generic array ref
Then you can write a typeof function that looks at tags to decide what
to do.
This shouldn't be that hard to see: an implementation of Scheme or
Lisp doesn't require an infinite family of tags in the lower-level
implementation.
--
Neel Krishnaswami
neelk at cs.cmu.edu
More information about the Python-list
mailing list