[Python-Dev] type categories
Martin v. Loewis
martin@v.loewis.de
15 Aug 2002 00:42:46 +0200
Oren Tirosh <oren-py-d@hishome.net> writes:
> Nope. For me protocols are conventions to follow for performing a certain
> task. A type category is a formally defined set of types.
ODP (Reference Model For Open Distributed Processing, ISO 10746)
defines that a type is a predicate; it implies a set (of which it is
the characteristic function).
By your definition, a type category, as a formally-defined means to
determine whether something belongs to the category, is a predicate,
and thus still a type.
> For example, the 'iterable' protocol defines conventions for a programmer
> to follow for doing iteration. The 'iterable' category is a set defined
> by the membership predicate "hasattr(t, '__iter__')".
It is not so clear that this is what defines the iterable category. It
could also be defined as "the programmer can use to for doing
iteration, by means of the iterable protocol".
> Protocols live in documentation and lore. Type categories live in the same
> place where vector spaces and other formal systems live.
By that definition, I'd say that Andrew's list enumerates protocols,
not type categories: they all live in lore, not in a formalism.
> A category is defined mathematically. A protocol is a somewhat more fuzzy
> meatspace concept.
A protocol can certainly be formalized, if there is need. Of all the
possible interaction sequences, you define those that follow the
protocol. Then, an object that follows the protocol in all interaction
sequences in which it participates is said to implement the protocol.
> > Again you've lost me. I expect there's something here that you assume
> > well-known. Can you please clarify this? What on earth do you mean
> > by "A Python expression is not a pure function" ?
>
> A function whose result depends only on its inputs and has no side effects.
> In this case I would add "and can be evaluated without triggering any
> Python code".
For being a pure function, requiring that it does not trigger Python
code seems a bit too restrictive.
In any case, I think it is incorrect to say that a Python expression
is not a function. Instead, it is correct to say that it is not
necessarily a function. There are certainly expressions that are
functions.
Regards,
Martin