[Python-3000] my take on "typeclasses"

Talin talin at acm.org
Fri May 12 07:24:02 CEST 2006


Mike Krell wrote:
> On 5/11/06, Guido van Rossum <guido at python.org> wrote:
> 
>>I think I'm more comfortable with a maximal taxonomy. In a maximal
>>taxonomy, I'd describe a large set of invariants, attributes,
>>behavior, etc., and say e.g. "this is how a file behaves". A
>>particular class can then claim to be a file by explicitly declaring
>>this (how that's spelled is a different issue -- it doesn't need to be
>>done by inheritance from an abstract base class or interface, it could
>>also be an arbitrary property, agreed upon by convention, or an
>>external registry of all file types, for example).
> 
> 
> If the route chosen is "agreed upon by convention" what is the
> difference between this and duck typing?  Are the "claim" and
> "convention" anything more than comments in the code?

The types that we are talking about are nothing more than duck types, so 
you are right about that part.

What's different is what we want to be able to *do* with the types.

A lot of modern programming languages get their power by being able to 
do reasoning with types. Virtual functions, generic functions, 
inheritance, multiple inheritance, polymorphism, and all these other 
aspects of typing can be thought of as a kind of "type calculus" - in 
other words, they are all a kind of mathematical function where one or 
more of the parameters is a type, and the result is different depending 
on what types you put into it.

The basic push behind this thread is to be able to do a similar kind of 
type calculus on duck types. Naturally, since the duck types have a more 
ambiguous definition than explicit types, the resulting calculus will 
need to be able to handle ambiguity (at the very minimum, by reporting 
it as an error.) But "fuzzy logic" can be just as formal and 
well-defined as "crisp logic".

-- Talin


More information about the Python-3000 mailing list