Multiple dispatch (Re: Q: Python 2.0 preliminary features?)

Martin von Loewis loewis at informatik.hu-berlin.de
Thu Oct 28 14:21:23 EDT 1999


Greg Ewing <greg.ewing at compaq.com> writes:

> > Neither, you should get a "message ambiguous" error
> 
> That's a reasonable answer. Although you still need some
> set of rules for defining when a call is ambiguous or
> not. I think I can sort of see what rule you're using
> here, but it's not easy to state concisely.

You can phrase the requirement two different ways: Given a the
half-ordered set of signatures (sig a is 'more derived' than sig b if
all arguments are 'more derived'), there is a sufficient static
requirement:

   The set of signatures must form a lattice.

(i.e. even though it is only a half order, for each pair (a,b) of
signatures that don't compare, there must be a third signature c,
with c 'more derived' than a and c 'more derived' than b).

Alternatively, you could phrase it as a dynamic condition (which would
be more Python-like): Given an invocation, there is a set of candidate
signatures (so that the actual argument types are 'more derived' than
the paramter types of each candidate). The invocation is ambiguous if
this set of candidates is not a lattice.

Hope this helps,
Martin




More information about the Python-list mailing list