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) {...}

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

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