This:

    multi sub is_equal(Integer $a, Integer where { $_ == $a } $b: ) { 1 }

hurts.  At least as I've been given to understand it[*], is impossible
to implement, because the second parameter's type can't be precalculated
in order to prepare for MMD dispatching.

The type object describing $b cannot be pre-constructed.  Its 'where'
clause is a closure that must capture the value of a passed value of
$a.  The subroutine object describing the where clause closure will be
different every time, as the stack frame containing $a is different
every time (perhaps even being called recursively).  Therefore, every
time $b has to be instantiated, a new type object has to be created
first to describe it.

In short, $b has no pre-calculable type.  And you can't calculate the
MMD potential of a subroutine unless you know the actual types of its
MMD-participating parameters.

(This also means that the type of &is_equal:(...) is impossible to
express, unless I greatly misunderstand the &foo:() syntax.  But
it doesn't matter what you call it if you can't call it.)

If you *really* *do* want MMD to include arbitrary boolean tests that
make Perl decide "this is not the MMD you are looking for", maybe you
should introduce an internal Perl 6 exception type which would be
interpreted by MMD dispatch to mean that.  Then you could emit that
exception as late as you want, after doing as many tests as you think
appropriate:

    multi sub is_equal(Integer $a, Integer $b) {
        $a == $b or die Perl6.MMD.Jedi_mind_trick;
        1;
    }

Without precalculable types, that's pretty much the best semantic you
can hope for.  May as well let the sub body use it too.

PS: Of course this example also implies that each parameter's
    declaration introduces a new lexical scope to its right.  But that
    bridge was crossed when you allowed earlier parameters to
    participate in the calculation of default values for later ones.
    At least it doesn't interfere with MMD.

[*] Autrijus introduced me to this construct, so unless the response
    is "we changed our mind" ...
-- 
Chip Salzenberg <[EMAIL PROTECTED]>

Reply via email to