PEP 3107 and stronger typing (note: probably a newbie question)

Diez B. Roggisch deets at
Thu Jun 21 09:01:47 CEST 2007

kaens schrieb:
> On 6/20/07, Diez B. Roggisch <deets at> wrote:
>> That is exactly the problem - there is no "some more" static typing.
>> There is static typing - or not. You can't have it "just a bit".
> Couldn't a language be made so that if you declared a variable like, say:
> string foo = "I'm a string"
> it would be a string, and always a string, and if you declared a 
> variable like
> foo = "i'm a dynamic variable"
> it would be considered dynamic?
> This doesn't seem like it would be too hard to add in to a language
> that already had dynamic typing (But then again, I am inexperienced -
> although interested in - language design).

It isn't too hard. All it needs is a bucket at a name that contains a 
type reference.

But what you DO with that is the hard thing. Just enforcing types at 
runtime is easy. Making JIT-compilation for such code and then put 
guarding statements around it - somewhat harder, but easier than full 
type inference.

But the OP wanted compile-time static typing checks. And _thats_ 
virtually impossible unless _everything_ is statically typed. And even 
if it is, the ClassCastExceptions of Java prove that.

Take this classic example from the java-world that is statically 
correct, but will fail at runtime

class A

class B extends A

B[] bs = new B[100];
A[] as = bs;
as[0] = new A();

The problem here is that the as-array has less type information, and 
because of polymorphism rules is allowed to actually hold an B-array. 
But that can't allow mere A-objects to be assigned to it!

So the JVM introduces a runtime type check here.

Mixing static and dynamic type information like proposed will only make 
this problem more severe, as you know even less about your types. Thus 
the whole purpose of static checking vanishes, and the whole thing 
shifts to a purely runtime checking.

> It seems to me like this could be really useful, but I'm not aware of
> any language implementing something like this.

Which _might_ be a hint... :)


More information about the Python-list mailing list