[Types-sig] Re: Types-SIG digest, Vol 1 #13 - 2 msgs

Tim Peters tim_one@email.msn.com
Tue, 1 Dec 1998 05:11:00 -0500

> ...
> if you want to use declarations, you'll have to write 100% type-
> consistent code whenever declared entities are involved -- and known
> to be type-consistent at compile-time.

> Do you think that "whenever declared entities are involved" means
> that typed python will not be able to exist with untyped python
> in any app?

Oh no, not at all.  There's nothing wrong in mixing things, and some of the
*goals* people have in mind likely require mixing 'em.  As a dumb but
suggestive pseudo-example, the ": Int" here

num: Int = 0
for thing in sequence:
    if predicate(thing):
        num = num + 1

could be used as a hint to the compiler that "num" needn't support the
runtime burden of a full reference-counted int-in-a-box implementation,
while saying nothing about the types of thing, sequence or predicate.
People will eventually get around to demanding an "everything in this module
*must* be declared!" pragma too, of course.

Until the details are fleshed out, it's hard to guess whether it will be
more pain or gain (if it were obvious now, 1/3rd of this SIG wouldn't be

> I would hope that we could limit the type declarations to a single
> module, and let untyped python use that module.  Otherwise, it seems
> like the entire standard lib will have to exist in 2 forms, typed and
> not

That needn't be:  if the "most general" type is (say) called Object, then in
an optional static-typing world anything that isn't explicitly typed is
implicitly typed as Object.  And anything can be passed where an Object is
expected, so untyped functions can be passed anything (explicitly typed or
not).  Passing an Int where an Object is expected is fine; the other way
around is not.  So the whole std library works without change, although it
would be naive to believe there wouldn't be increasing pressure to spin off
typed variants (e.g., a typed variant of "math" that accepted only
declared-to-be floats, so it could skip the runtime "is this thing a float
or what?" checks).

People who have used C++ templates extensively will have a feel for what an
enormous amount of code bloat this can lead to (Stroustrup often recommends
that templates do casted inline redirection to a void*-slinging base class
to avoid that).  It's not *all* roses and bleeding gums <wink>.

confusion-is-healthy-ly y'rs  - tim