so back to foo("bar"). What's the default behavior? String doesn't Num,
does it? though is does convert if the value is good.... 

Does that mean foo("123") should or should not dispatch to foo(Int)?
Or even foo(Num), for that matter.... Oy, I could see some headaches
around setting these rules in mind, lol.... What's the DWIMmiest
behavior hear?

I assume foo(1) would dispatch to foo(Int) rather than foo(Num), as the
most restrictive fit, and I could see how that could blow up in my
face. Is there some basic compile time warning (and a way to tell it
"shut up, I know what I'm doing") that says "hey, these are
suspiciously close signatures, are you sure this is what you wanted?"

Is the difference that foo("123") can be easily converted to foo(123)
without data loss, whereas foo("bar") to foo(0) cannot?

--- Jonathan Scott Duff <[EMAIL PROTECTED]> wrote:
> 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.  :-)


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Reply via email to