Python from Wise Guy's Viewpoint

Matthias Blume find at my.address.elsewhere
Tue Oct 28 23:55:08 EST 2003


Pascal Costanza <costanza at web.de> writes:

[ on my claim that every dynamically typed program has a statically typed
  translation: ]
> No, that's not all you need to do. Essentially you would need to write
> a complete interpreter/compiler for the dynamically typed language on
> top of the statically typed one, _if_ you want runtime
> metaprogramming. That's not what I would call a straightforward
> translation.

Actually, I didn't say what I need, so how can you contradict me on
this point?  Anyway, having to have a compiler/interpreter around is
only true if the original program contained a complete
compiler/interpreter, in which case I'd say this is just par for the
course.

> > [This whole discussion is entirely due to a mismatch of our notions of
> > what constitutes expressive power.]
> 
> No, it's not. There's a class of programs that exhibit a certain
> behavior at runtime that you cannot write in a statically typed
> language _directly in the language itself_.

This is simply not true.  See above.

> There's no program that
> exhibits a certain behavior at runtime that you can only write in a
> statically typed language. [1]

I do not dispute this fact.

> [11 Except perhaps for a class of programs that would change their
> runtime and/or space complexity, provided they would need lots of
> dynamic type checks.

This comment makes me /very/ uneasy.  Namely, the funny thing here
is that you seem to question a statement that you make /yourself/ even
though it is undoubtedly true.  *Of course* you can write everything
that can be written in a statically typed language in a dynamically
typed language in such a way that runtime behavior is the same
(including complexity).  Translating a well-typed ML program into,
say, Lisp is completely straightforward.  (Early ML implementations
were done that way.)

The proof of type-safety for the original ML program also shows that
no additional runtime checks are needed for the result of the
translation.  You don't even need the runtime checks that Lisp does on
its own because it doesn't know any better. (This is unless you turn
these checks off explicitly -- which in general would make the code
unsafe but in this specific case does not.)

So rest assured that the answer to your question:

> But I haven't sorted out yet whether this class
> really exists.

is "no".  But that was not my point anyway.

Matthias

PS: You don't need to try and convince me of the virtues of dynamic
typing.  I *come* from this world -- having implemented at least three
(if not four -- depending on how you count) interpreters/compilers for
dynamically typed languages.  Because of this I also already know all
the arguments that you are undoubtedly thinking of bringing forward,
having either used them myself or once marveled at them when I heard
them from other, then like-minded folks.  But the long-term effect of
working with and on such systems was that I now prefer to avoid them.
"Run-time metaprogrammming" you say?  The emperor has no clothes.




More information about the Python-list mailing list