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

Alex Martelli aleaxit at yahoo.com
Fri Mar 9 07:10:46 EST 2001


"Hamish Lawson" <hamish_lawson at yahoo.co.uk> wrote in message
news:mailman.984131592.17401.python-list at python.org...
    [snip]
> Wouldn't there be a hierarchy of interface types for file-like objects,
> with some interfaces specifying more methods than others? You'd then

It probably wouldn't be a hierarchy -- there is no special sense
in which any of .read, .readline, .readlines, .xreadlines is "more
fundamental" than any of the others (Haskell's typeclasses are the
best way I know to express such common situations -- methods can be
defined in a mutually recursive way in the typeclass, the types that
are its specific instances may break the recursion any way they like,
and client-code gets all the desirable usage convenience).

> choose the interface type that specified the collection of methods that
> you require of your passed object.

Any of the 2**4-1 non-empty subsets of the above 4 may make
sense.  Why invent 15 names for the subsets?  The collection
of methods that you require is exactly the set of methods
you will actually call.  Interfaces may have their uses (I'd
LOVE a way to get Haskell typeclasses in Python!-) but this
doesn't seem to be a particularly useful one.


Alex






More information about the Python-list mailing list