Getting started

Adam Taylor ataylor at ucsd.edu
Tue Sep 24 21:36:06 EDT 2002


About this:

Alex Martelli wrote:
 > I'm somewhat surprised at seeing you make such assertions at
 > obvious variance with type theory -- I thought you had a solid
 > CS background (stronger than my own -- I'm just an engineer,
 > more interested in pragmatics than in theory).  We _do_ share
 > the fundamentals, I hope?  E.g., my favorite "essential Luca
 > Cardelli bibliography":
 >
 > Cardelli, Wegner, "On understanding types, data abstraction, and
 > polymorphism", ACM Computing Surveys 1985
 >
 > Cardelli, "Type Systems", in "Handbook of Computer Science and
 > Engineering", CRC Press, 1997.

This last is available at:
http://research.microsoft.com/Users/luca/Papers/TypeSystems.pdf

It says, in part:

   A program variable can assume a range of values during the execution
   of a program.  An upper bound of such a range is called a type of the
   variable. For example, a variable x of type Boolean is supposed to
   assume only boolean values during every run of a program. If x has
   type Boolean, then the boolean expression not(x) has a sensible
   meaning in every run of the program. Languages where variables can be
   given (nontrivial) types are called typed languages.

   Languages that do not restrict the range of variables are called
   untyped languages: they do not have types or, equivalently, have a
   single universal type that contains all values. In these languages,
   operations may be applied to inappropriate arguments: the result may
   be a fixed arbitrary value, a fault, an exception, or an unspecified
   effect. The pure \lambda-calculus (see Chapter 139) is an extreme case
   of an untyped language where no fault ever occurs: the only operation
   is function application and, since all values are functions that
   operation never fails.

Based on this definition, it seems to me that Python _is_ untyped,
since the type of a variable can change arbitrarily in mid-program.

He later discusses the distinction between safety and typed-ness, and
shows this table:

          Typed   Untyped
Safe     ML      LISP
Unsafe   C       Assembler

Python is safe (at least pure Python, I think), so it should go in the
same square as Lisp, correct?

Cardelli doesn't use the term "weakly typed" himself, but on page 5 he
seems to be say that "weakly typed" is the commonly used term for what
he calls "weakly checked".  C is weakly checked, in his terminology, and
that's why it's unsafe.

But people on this thread seem to be using "weakly typed" to mean
roughly the same thing as Cardelli's "untyped".  Which is fine, and
pretty close to Cardelli's terminology.  But clearly the terms "untyped"
(=="weakly typed" on this thread) and "weakly checked" (=="weakly typed"
in common usage) are very different things.

Adam

-- 
Adam Taylor
ataylor at ucsd.edu
858-534-4763





More information about the Python-list mailing list