On 03/19/2014 11:06 AM, Damian Conway wrote:
> To me, the issue is: how does Perl 6 actually carry out the
> type inference we're doing here?
> 
> And I believe it's an important question to get right, as we
> may eventually see Perl 6 doing more type inference...either
> in core, or else through some nefarious module that some
> evil genius eventually writes. ;-)
> 
> If Perl 6 does type inference on some $value simply by calling
> $value.WHAT, then:
> 
>     multi foo(0|1) {...}
> 
> should indeed be equivalent to:
> 
>     multi foo(Junction $ where 0|1) {...}
> 
> 
> However, that's not the only possibility (nor, in my opinion,
> the most predictable or useful).
> 
> If, for example, Perl 6 did type inference by calling an internal:
> 
>     multi infer-type (Any $value) { $value.WHAT }
> 
> then:
> 
>     multi foo(0|1) {...}
> 
> would be equivalent to:
> 
>     multi foo(Int|Int $ where 0|1) {...}
> 
> which is, of course, just:
> 
>     multi foo(Int $ where 0|1) {...}

No.

The type of Int|Int is still Junction, not Int.

However you turn the problem, you'll need some form of special-casing to
fold Int|Int into Int, and please formulate it so that the Mu case
continues to work.

To spin the tale further, we need to think about what happens if
somebody writes

multi foo(1|2e0) { ... }

so now we have Int|Num. We could explore the most-derived common
ancestor (Cool), or look into role space (Real, Numeric come to mind),
or simply error out.

> which, in my view, would be a much more useful outcome in the vast
> majority of cases.

Agreed. We "just" need to come up with a consistent, intuitive way to
handle the rest of the cases. And implement it.

Cheers,
Moritz

> I accept that it's important to be able to explicitly declare a
> parameter as a Junction, so it's immune to junctive autothreading,
> but I don't think that should be the norm...and certainly shouldn't
> happen implicitly. That's why variables, parameters, and return values
> that are not explicitly typed default to Any, rather than to Junction.
> 
> And, I think this is another implicit case where a non-junctive outcome
> would be more useful...and more widely expected.
> 
> In other words, for the one time in a thousand (or fewer) where I
> actually want:
> 
>     sub foo(Junction $ where 0|1) {...}
> 
> then I should have to be explicit about that argument being junctive
> (because I should *always* have to be explicit about an argument being
> junctive).
> 
> And for the 999 times I want:
> 
>     sub foo(Any $ where 0|1) {...}
> 
> I should be able to just write:
> 
>     sub foo(0|1) {...}
> 
> 
> Damian
> 

Reply via email to