[Python-3000] Use cases for type annotations? (WAS: Type parameterization)
Phillip J. Eby
pje at telecommunity.com
Sun May 21 18:41:59 CEST 2006
At 08:51 PM 5/20/2006 -0600, Steven Bethard wrote:
>I'd particularly be interested in an example where overloading
>implies() to do something other than issubclass comparisons solves a
>real problem.
The prototype overloads implies() to allow a generic function to imply any
type that can be passed to the generic function.
The flatten() example then uses this by defining a dummy 'iter()' generic
function.
RuleDispatch is of course another example; it has its own 'implies()'
protocol that is used in basically the same way. Of course, it has lots of
types that implement implies(), since it supports isinstance(),
issubclass(), comparison operators, object identity checks, etc. So
anything that people use RuleDispatch for is essentially a "real problem"
being solved by overloading of implies().
The Overload3K implementation is a restricted subset of what RuleDispatch
does, in that Overload3K never performs tests directly on arguments, only
on the arguments' types. However, a RuleDispatch implementation based on
Overload3K could still use the same implies() function that Overload3K
does, albeit only for inter-signature priority comparisons.
Anyway, the main thrust of the prototype was to answer the then-current
discussion about interfaces and typeclasses and the like. I wanted to show
that an open-ended system (based on the 4 concepts in my post immediately
previous to this one) would allow interfaces, typeclasses, or whatever the
heck else people want, to be implemented through a common base system that
would also be extensible to full predicate dispatching for people who want
that.
More information about the Python-3000
mailing list