develooper Front page | perl.perl6.language | Postings from June 2006

Re: Can foo("123") dispatch to foo(Int) (was: Mutil Method Questions)

Thread Previous | Thread Next
Jonathan Scott Duff
June 23, 2006 11:53
Re: Can foo("123") dispatch to foo(Int) (was: Mutil Method Questions)
Message ID:
On Fri, Jun 23, 2006 at 09:11:44PM +0300, Markus Laire wrote:
> And what about other types?
> e.g. if String can't ever be "best candidate" for Int, then does that
> mean that neither can Int ever be "best candidate" for Num, because
> they are different types?

Well, I think Num and Int *aren't* different types because as far as
duck typing goes, Num does Int.  I wouldn't expect that String does
Int though (at least not without some help :).

The way I see it, the types specified in the signature are like
constraints.   When you say

    sub foo (Num) { ... }

the signature says that "only an item that can perform the Num role may
fit in this slot". When perl tries to match Capture to Signature,
it checks the type of each argument in the Capture against the 
"does list" for each parameter in the Signature.  If the argument type
appears in the "does list" of the Signature, then it's a match and all
is well.  Otherwise it's an error.  Since "Num does Int", a call such
as C<foo(10);> succeeds.

At least that's my vague interpretation of this aspect of perl6 at
this moment.  :-)

Jonathan Scott Duff

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About