[Python-Dev] Ridiculously minor tweaks?
12 Mar 2003 09:06:10 -0500
Guido> Python is a dynamic language, and you can do whatever you want
Guido> with the data structures it gives you. But when thinking about
Guido> extending the language with optional type declarations or
Guido> automatic type inference, I always think of the type of a list
Guido> as "list of T" while I think of a tuple's type as "tuple of
Guido> length N with items of types T1, T2, T3, ..., TN". So [1, 2]
Guido> and [1, 2, 3] are both "list of int" (and "list of Number" and
Guido> "list of Object", of course) while ("hello", 42) is a "2-tuple
Guido> with items str and int" and (42, "hello", 3.14) is a "3-tuple
Guido> with items int, str, float".
It might interest you to know that Standard ML, which is statically
but polymorphically typed, draws exactly that distinction. It has
both tuple and list types. The type of a tuple includes the type of
each of its elements, whereas all of the elements of a list must be
the same type. Moreover, although the type of a list includes the
type of its elements, it does not include how many elements there are.
So in ML, the type of [1, 2, 3] is "int list", and the type of
("hello", 42) is "string * int".
Andrew Koenig, email@example.com, http://www.research.att.com/info/ark