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

Dominic Binks dominic.binks@aethos.co.uk
Mon, 30 Nov 1998 09:23:00 +0000

Justus Pendleton <justus@acm.org> wrote:
> To catch these kinds of problems is it really necessary to have a static
> typing system or could kjpylint be enhanced so that it could catch these
> kinds of things?  I realize that it probably couldn't catch every possible
> strange case that might arise using Python, but what if it could notice 80%
> of them and on the rest say,
> "There's something strange going on around line 562, you might want to double
> check that you aren't making a mistake there."

Although I think that the aims of a static type system that can cover
everything Python can is a great idea.  I would just like something just
like this.  Something that says you passed something that was an int to
something that's a string, so on your own head be it.  If it had to give
up and say eventually with something and declare

	def f(x,y):

to a be a function that takes two anythings (possibly the same, more
likely different) and returns an anything, that would be fine.  I would
say that most code does not follow this example.  I would hazard a guess
that may be as much as 90% of Python code is regularly type following.

Ok, the part that isn't may mean that the rest of the code cannot be
typed easily, but I'd still reckon that most functions can be typed
quite easily.

There are lots of parts of Python that pose problems for type systems. 
The following example is just one (that I don't think has been given
before, but I may be wrong in that)

	def f(x):
		if type(x) == StringType:
		elif type(x) == IntType:

Then x can legitimately take either an Int or a String, which is
possibly quite hard to code in a type system.

I worked with a language which was a successor to Prolog which had no
var predicate.  var was used in very similar situations to type().  The
decision from the designer was var would never be implemented so you
just had to provide two functions rather than one.  Obviously this is
not possible to do in Python, so the type system would need to be able
to handle this.

Dominic Binks/Systems Engineer/Aethos Communication Systems Ltd.
400 Park Avenue/Aztec West/Bristol/BS32 4TR/United Kingdom
Tel: +44 1454 614455/Fax: +44 1454 620527/Mobile: +44 498 693964
E-mail: dominic.binks@aethos.co.uk