Static typing (was Re: Java guy interested in Python)

Michael Hudson mwh21 at cam.ac.uk
Fri Mar 9 06:52:04 EST 2001


=?iso-8859-1?q?Hamish=20Lawson?= <hamish_lawson at yahoo.co.uk> writes:

> Michael Hudson wrote:
> 
> > If you type-annotate this, you might write (using entirely made up
> > syntax):
> > 
> > def write16(file : <file>, int : <int>):
> >     file.write(struct.pack("h",int))
> > 
> > but then what about passing in a StringIO object, or some user 
> > wrapper of a file object?  What makes a "<file>"?  At the moment, 
> > it's just a loose collection of methods, some of which are optional 
> > in some circumstances.
> 
> Wouldn't there be a hierarchy of interface types for file-like
> objects, with some interfaces specifying more methods than others?
> You'd then choose the interface type that specified the collection
> of methods that you require of your passed object.

Well, that might be possible, but 
(a) there isn't one, presently
(b) you'd certainly have fun trying to make the heirachy a DAG.

I suspect that you'd basically end up listing the methods required,
eg:

def func(file : <has 'write', 'read', 'seek'>, ...):
    pass

I'm not sure that makes a "type system".  Hmm.  More thinking
required.

Cheers,
M.

-- 
  The use of COBOL cripples the mind; its teaching should, therefore,
  be regarded as a criminal offence.
           -- Edsger W. Dijkstra, SIGPLAN Notices, Volume 17, Number 5



More information about the Python-list mailing list