does lack of type declarations make Python unsafe?

Terry Reedy tjreedy at udel.edu
Mon Jun 16 16:31:06 EDT 2003


"Moshe Zadka" <m at moshez.org> wrote in message
news:mailman.1055775776.27192.python-list at python.org...
> On Mon, 16 Jun 2003, "Terry Reedy" <tjreedy at udel.edu> wrote:
>
> > If one considers the set of values as part of the type, this
amounts
> > to saying that the type system of most languages is too coarse for
> > real needs.  Many operations need counts [0, 1, 2, ...].  Python
does
> > not have this, C only backhandedly (unsigned int, like calling an
int
> > an unfractionated rational).  A few need a count subset: circular
> > queues need residue classes [0, 1, ..., n-1] with all operation
> > results taken %n.  These are well-defined mathematical sets that
> > programmers usually have to simulate rather than simply declare.
>
> Sure...
> Some operations need primes (e.g., RSA encryption).

My use of 'set' above was meant to be stronger than you took it.
Types are about values combined with operations thereupon, not just
values. Residues mod n form an algebra (ring?) closed under +,-, and
*, just like integers, whereas primes are not closed under any known
operation.  In fact, fixed-sized computer ints are either *not* closed
(and therefore less valid as a type than residue classes) or else are
actually residues mod (bits-per-int).  So it is hardly silly to
imagine a language that allowed a variable rather than fixed mod
value.

> Some operation  need strings which specify programs which halt
(think "exec" :).

Since membership in this class cannot be tested, it is not even an
operationally defined set.  Note that Python does effectively define
and test for a subtype of (unquoted) strings, namely names, which are
closed under catenation but not slicing.

Terry J. Reedy






More information about the Python-list mailing list