Python from Wise Guy's Viewpoint

Fergus Henderson fjh at
Tue Nov 11 12:06:59 CET 2003

Pascal Costanza <costanza at> writes:

>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?

In Haskell you would just use "Dynamic" instead of the above, and be done
with it.  In Mercury, you'd just use "univ".

In SML, I don't know.  Probably none.  In fact, the first two entries in
the type above are not really necessary, you could just represent ints
and strings as Atoms.  Even Apply could be represented using just Cons
and Atom: instead of Apply x y, we could use Cons (Atom "apply") (Cons x y).

>> Note that our symbol table includes an entry for the function "define",
>> so that eval can be used to modify the dynamic bindings.
>DEFUN is just one example. What about DEFTYPE, DEFCLASS, DEFPACKAGE, and 
>so forth...

Well, DEFTYPE in lisp really just defines a function, doesn't it?
So that's not much different than DEFUN.  Likewise, DEFCLASS just
defines a collection of functions, doesn't it?  OK, maybe these
also record some extra information in some global symbol tables.
That is easily emulated if you really want.

I don't know exactly what DEFPACKAGE does, but if the others are any
guide, it's probably not too hard either.

Fergus Henderson <fjh at>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <>  |     -- the last words of T. S. Garp.

More information about the Python-list mailing list