[Python-Dev] FW: multimethod-0.1
Thu, 15 Aug 2002 15:58:46 +0200
>> I haven't studied this, but from a quick glance it looks competent.
>> Multimethod-0.1 is another python module for implementing multimethods
>> (a.k.a. generic functions, multiple-argument method dispatch). This
>> one features:
>> - support for Python2.2 type/class unification
It works only with new style classes and types, not with old style
classes, don't know if it's a problem, in the latter case
mutability of __bases__ becomes a problem.
>> - a precedence graph for more efficient dispatching
>> - a best-fit resolution algorithm, in which the method closest in
>> inheritance distance is called
This makes me uneasy, either we go the CLOS way where lefter
arguments take priority, or the Dylan way, i.e. in face of ambiguity
throw an exception (in that case we could add a mechanism to
force disptach on a supplied supertype like my _redisptach).
>> - a versatile 'call-next-method' or 'super' function.
FYI which uses a dictionaries on frames
>It's a good start, but from the docs it doesn't appear to deal with:
it's a start
>a. Type categories -- it seems as though the only way for a multimethod
>implementation to match an actual argument is if the formal argument has an
>inheritance relationship with it.
but it's really an orthogonal problem (the concrete problem wrt
multidispatch is just how to merge categories in the mro),
make categories/protocols firtst class is a different can of worms.
>b. Implicit conversions -- If I declare a function that accepts a Python
>int, can I pass a Python float?
maybe if it accepts a float you can pass an int <wink>. I see the issue
but I don't know if this should be the default on the Python side in general.
It should be configurable for the single multimethod.
c. there should be a version that can be put in class a and behave
like a method (e.g. to implement the moral of overloading) producing
bound and unbound in the first argument versions when retrieved through the
class or instances, it should probably take a function to be called
in case no matching method is found, this can be used to redispatch
to the super classes, or something similar, unless we want to redifine how the