Python from Wise Guy's Viewpoint

Don Geddis don at geddis.org
Tue Oct 28 13:48:45 EST 2003


Andreas Rossberg <rossberg at ps.uni-sb.de> writes:
> I should note in this context is that static types usually express different
> things than dynamic ones, especially when it comes to number types. In Lisp,
> the runtime tag of a number will usually describe the representation of the
> number. This may well change between operations. But static typing, at least
> in high-level languages, is about semantics. If I choose a certain integer
> type I do so because it has the desired domain, which I want to have checked
> - I'm not at all interested in its representation.

Types don't have to be disjoint.  In Lisp, if a data object is a FIXNUM,
at the same time it's also a NUMBER.  And perhaps an (INTEGER 0 16) too.

Yes, at least one of the types defines the representation.  But there are
semantic types as well.

As to "change between operations": it doesn't matter what your type system is.
Any function call has the potential to "change types".  It would be a silly
system that requires the (type) domain and range of every function to always
be identical.

> In fact, values of IntInf are likely to have multiple representations
> depending on their size, but the type is invariant, abstracting away from
> such low-level representation details.

And Lisp's NUMBER type also has multiple representations.  And the SQRT
function takes a NUMBER and returns a NUMBER.  But also, at the same time,
it takes INTEGERs and returns FLOATs, and takes negative INTEGERs and returns
COMPLEX NUMBERs.  Semantics and representation, all at the same time!

> Actually, I think dynamic typing should abstract from this as well, but
> unfortunately this does not seem to happen.

But it does.

> Because the designers decided (rightly so, IMHO) that it is best to avoid
> implicit conversions, since they might introduce subtle bugs and does not
> coexist well with type inference.

Sounds like a tradeoff.  Perhaps, for some programmers, the freedom you get
with implicit type conversions is more valuable than the benefits of type
inference?

        -- Don
_______________________________________________________________________________
Don Geddis                  http://don.geddis.org/               don at geddis.org




More information about the Python-list mailing list