develooper Front page | perl.perl6.internals | Postings from July 2002

Re: vtables and multimethod dispatch

Thread Previous | Thread Next
From:
Dan Sugalski
Date:
July 10, 2002 08:02
Subject:
Re: vtables and multimethod dispatch
Message ID:
a05111b02b951f99c49ba@[63.120.19.221]
At 8:35 PM -0700 7/9/02, John Porter wrote:
>Dan Sugalski wrote:
>>  John Porter wrote:
>>  > Why is "left side wins" insufficient?
>>
>>  Well, perl 5 is apparently not left side wins for overloading, which
>>  is enough.
>
>Mmmm.  Have a good example handy?

I'll have to go dig one up. Damian hit me with the "Perl does it" at 
YAPC, and I generally take what he says at face value. (Often with 
aspirin as well, but that's a separate issue)

>But even so, I'm not sure that should be a problem, since we're
>talking about multimethods at the vm interpreter layer; we should
>expect (shouldn't we?) that a compiler will be able to transform
>expressions with overloading into bytecode that does the right
>thing even in a left-side-wins scheme.

Well, sort of. The interpreter, in the general case, can't know if 
things are overloaded without the compiler doing full dataflow 
analysis, and that's deep into the Hard Problem realm. What we're 
doing is assuming we don't know and letting the variables decide 
whether they'll care. Perl's will, though other languages can decide 
differently.

>  > If there's an int on the left and a float on the right,
>>  the math is still done floating-point.
>
>Yes.  My first inclination is to say that this is a rather special
>case, since the types are intrinsic, and there are only two of them.
>That means that a complete elaboration is feasible, so there's no
>issue of which side wins; you'll always get a perfect match.
>
>But the more general problem is (presumably) always a possibility,
>so we have to address it.  As in the case of int-vs-float, maybe a
>kind of "paper-scissors-rock" rulebase that orders types.
>(What C/C++ hard-codes as "type promotion".)

Type promotion makes me more nervous than multimethod dispatch. I 
think I'd rather not do that unless we really have to.

>If no match is found in the rulebase for the 2 (n?) types
>involved, then we could fall back to left-side-wins.

If we can't find a match, or if there are two equal-distance matches 
with no clear winner, we throw an exception. There'll be a mechanism 
to specify a default method. (Which, by default, will pitch an 
exception)

>Just a thought.
>
>Btw, I think the "distance in type space" idea is pretty kewl...
>but the thought of actually using it in parrot gives me thewillies.

Heh. I never expected to have to dust off my trig skills when I 
started this. If I need to dig out the calculus books, I think I'll 
just go run screaming...
-- 
                                         Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
dan@sidhe.org                         have teddy bears and even
                                       teddy bears get drunk

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About