[Python-ideas] Democratic multiple dispatch doomed to fail (probably)

ntoronto at cs.byu.edu ntoronto at cs.byu.edu
Sat Dec 15 09:07:14 CET 2007


I wrote:
> The application implements a social choice function: it picks a winner
> function based on types' "preferences". Arrow's Theorem doesn't care
> exactly how it does this - whether it has types vote or sums distances
> from whatever - it just says that however it does this, the result can't
> always be "fair". And "fair" doesn't even mean one type can't have more
> say than another by, for example, narrowing the subset first based on
> its own preferences. It only means that things don't act
> counterintuitively in general, that there's *some* means to every
> outcome, and that one agent (type) doesn't control everything.

Sorry to self-reply, but I was just reading this:

    http://dev.perl.org/perl6/rfc/256.html

"""
1. 2. 3. <Exact matches>

4. Otherwise, the dispatch mechanism examines each viable target and
computes its inheritance distance from the actual set of arguments. The
inheritance distance from a single argument to the corresponding parameter
is the number of inheritance steps between their respective classes
(working up the tree from argument to parameter). If there's no
inheritance path between them, the distance is infinite. The inheritance
distance for a set of arguments is just the sum of their individual
inheritance distances.

5. The dispatch mechanism then chooses the viable target with the smallest
inheritance distance as the actual target. If more than one viable target
has the same smallest distance, the call is ambiguous. In that case, the
dispatch process fails and an exception is thrown (but see "Handling
dispatch failure" below) If there's only a single actual target, its
identity is cached (to accelerate subsequent dispatching), and then the
actual target is invoked.
"""

This is almost precisely the Borda protocol:

    http://en.wikipedia.org/wiki/Borda_count

Borda does not satisfy independence of irrelevant alternatives. HOWEVER,
the proposed dispatch mechanism does.

Why? The agents are voting a kind of utility, not a preference. With the
addition or removal of a function, the sum of votes for any other function
will not change. AFAIK, that's the only Arrow-ish problem with Borda, so
this proposed dispatch mechanism doesn't have the problems I was
expecting. Big stink for nothing, I guess.

I imagine that making next-method calls behave is a nightmare, though. The
more I read about multiple dispatch, the less I like it.

Neil




More information about the Python-ideas mailing list