On Sat, Apr 19, 2008 at 08:00:07AM -0000, John M. Dlugosz wrote:
: Perl 6 has a concept of a "candidate list".  The candidate list are those 
that could handle the call, typically inherited methods and multi variations.  
: 
: It seems that multi variations, at least with respect to the semicolon 
parameters, compare the actual type and drop out of the list if any don't match.

When you drop those candidates that "can never match" is mostly a
matter of optimization, I suspect.

: What about ordinary methods (and ordinary parameters of multis)?  Does the 
candidate list hold every method name that matches, or does it do simpler 
parameter matching based on number of arguments, required named arguments, etc.?

For those parameters, it matters only whether they can be bound when the
candidate is called.  The parameters need not be considered at all when
generating the candidate list (but see "optimization" above--though
perhaps this view is oversimplified if we have to do tie determination,
since ties are supposed to fail before the final call, and we'd have
to weed out non-bindable sigs before declaring a tie).

: If that is the case, then a derived method might not hide a base class method 
if the parameter list is seriously incompatible.  More interestingly, 
left-to-right ordering of multiply-inherited base classes will be checked for 
applicability rather than  arbitrarily taking the leftmost.

"only" methods use only short name, and methods, like subs, default to
"only".  And as it is currently specced, the class is dispatched on
the short name before any any of its multis, and long names are not
considered until the class is dispatched to.  The invariant is that
single dispatch is always under the control of the invocant's object
system, while multiple dispatch never is.  In my mind the policy
distinction is clarified by considered what happens if a foreign
language defines some of the classes.  Under single dispatch the
language that defined the object gets the dispatch.  Under multiple
dispatch, all objects are treated as Perl objects with Perl types,
and the type system gets to decide which candidate to call.  It is
important to be able to look at a call and determine which kind of
call is being made; this is why we give single dispatch a syntax that
is distinct from multiple dispatch.

So if you use "multi method" declarations within a class, they appear
only to be a single method from outside the class, because that is all
the foreign language interface can support.  You can only use multi
methods within a class if the language supports the concept, and Perl
6 only supports it out the scope of the current class.  Basically,
multi methods are just treated as multi subs inside a class, except
the invocant is predecided and doesn't make any difference to the
dispatch within the class.

Larry

Reply via email to