[Python-Dev] type categories
Oren Tirosh
oren-py-d@hishome.net
Thu, 15 Aug 2002 09:13:35 -0400
On Thu, Aug 15, 2002 at 08:20:06AM -0400, Guido van Rossum wrote:
> > In a dynamically typed language there is no such thing as an 'integer
> > variable' but it can be simulated by a reference that may only point to
> > objects in the 'integer' category.
>
> This seems a game with words. I don't see the difference between an
> integer variable and a reference that must point to an integer.
> (Well, I see a difference, in the sharing semantics, but that's just
> the difference between a value and an pointer in C. They're both
> variables.)
In C a pointer and a value are both "objects". But Python references are
not objects. In a language where almost everything is an object they are a
conspicous exception. A slot in a list is bound to an object but there is
no introspectable object that represents the slot *itself*.
And yes, sharing semantics make a big difference.
My basic distinction is that type categories are not a property of objects.
An object is what it is. It doesn't need "type checking". Type categories
are useful to check *references* and ensure that operations on a reference
are meaningful. A useful type checking system can be built that makes no
change at all to objects and type, only applying tests to references. The
__category__ attribute I proposed for classes is not much more than a
convenient way to spell:
class Foo:
...
assert Foo in category
The category is not stored inside the class. It is an observation about
the class, not a property of the class.
Oren