[Python-3000] Adaptation vs. Generic Functions

Michael Chermside mcherm at mcherm.com
Thu Apr 13 16:54:48 CEST 2006


Martin v. Löwis replies to my story:
> Or, to make a long story short: there might not be a single next
> best candidate, but multiple, which are mutually equally-good:
> both mpz+object and object+array would match, and neither is
> better than the other.
>
> This is because they only form a partial order. Of course, it
> might be possible to impose a total order on top of it (e.g.
> giving the left-more operands higher precedence, or considering
> the order of registration). This all sound arbitrary, though.

That's a really good way of looking at it. Our current __add__()/
__radd__() system prefers the left argument. A multi-dispatch
function with the strict dominance rule refuses to prefer either,
raising an exception unless you register something to tell it what
to do. I believe that's a point in FAVOR of the multi-dispatch
function approach.

Adding multi-dispatch functions to Python is a BIG, DEEP change.
Similar, perhaps, to adding descriptors, not similar to adding a
"with" statement. That means great care should be exercised, but
also that great things are possible.

-- Michael Chermside



More information about the Python-3000 mailing list