[Prev][Next][Index][Thread]
Re: Multimethods 101 (was Re: Multiple dispatch (Re: Q: Python 2.0 preliminary features?))
Louis Madon wrote:
> """ snip """
> In the beginning Greg Ewing wrote:
>
> > Suppose AA is a subclass of A, and BB is a subclass of B,
> > and there are methods defined for the combinations
> > foo(A, B), foo(AA, B) and foo(A, BB).
> >
> > Now, if you make a call with the combination foo(AA, BB),
> > which method should get called?
>
> Several people said its "ambiguous".
It's ambiguous unless you define what should happen. To my mind the
apporpriate call would be to foo (A,B), but any one of them would be a valid
interpretation in the absence of language definitions. Depending on search
order, it would seem most Pythonish to call the foo (AA, B) method, since
that would probably be the first one found along the left hand branch of the
search path, and it does fit.
This is *definitely* not being offered as an argument against
multi-methods. It's merely a matter of defining the interpretation to an
agreed upon spec. The Python interpretation of class inheritance of methods
provides a language oriented background against which I would say that in
Python the choice should be to select foo (AA, B).
Follow-Ups:
References: