[Python-Dev] Multiple dispatch
Wed, 14 Aug 2002 13:54:44 +0200
>I don't know how these things usually work, but isn't it a bit early for
>that? I would like to have some discussion about multiple dispatch (and
>especially matching criteria) before investing in a formal proposal. That's
>what my earlier posting which got banished to the types-sig was trying to
>do. Getting a feel for what people are thinking about this, and getting
>feedback from those with lots more experience than I in matters Pythonic is
>important to me.
I'm interested in multiple dispatch [but have limited
band-width], once I have even written
a pure Python implementation of it (only on classes). It's quite
expressive for some designs. But:
[- Jython too internally uses a kind of multiple-dispatch
in order to dispatch to overloaded Java methods.
But such a mechanims is really quite a limited beasts
wrt to adding multiple-dispatch to Python in general. ]
- I'm not sure is that much Pythonic or easy to grasp,
one remark that I have read sometimes is that
with multimethods the program logic is easely scattered
in many places with so-to-say non-local effects.
- It is yet another paradigm that should be integrated
with the rest of Python. For example how does it interact
with the current single-dispatched methods, does it?
[It is not just a theoretical question, it influences whether
this can be used to model e.g. the dispatch of Jython for
overloaded Java methods or not, simplifying the picture
or adding confusion]
- Syntax and semantics: in Python definitions are assignments.
Now one needs at least a (maybe implicit) define generic function and
an add method to generic function. (Should def be abused?)
- Should all function (methods) definitions define generic function methods
under the hood.
- Do we dispatch on only foo.__class__ or
do we want to dispatch on protocols/interfaces/categories,
now at the moment these are not first-class in Python.
- How do we solve dispatch ambiguities, the more
predictable and uncomplicated the more Pythonic.
- Sometimes it is useful to substitute functions and methods
with wrapped re-editions, the equivalent for multi-method
are at least before,after,around combinators, I think
they are useful, but make the picture more complex.
So the question is more what is the most pythonic way
we can find to add multiple dispatch, then maybe it
is Pythonic enough or not. [It seems a SIG task
but I have not really written that word <.5 wink>]
Related: Smallscript, CLOS, Dylan, various overloading flavors
Smallscript is interesting because it adds multiple dispatch
to the single-dispatch semantics of Smalltalk, so it's
very overlapping with our case, OTOH I have not played
with it and I don't know the details of the actual semantics,
[and in general it gives a PL/I-esque impression, at least from far away].