Skip to content

Commit

Permalink
Share role curries use 6model parametrics.
Browse files Browse the repository at this point in the history
This means that Positional[Int] will always lead to the same type
object (or at least, will once the pre-comp bits of 6model parametrics
are also implemented). This resolves various errors like "expected
Array[Str] but got Array[Str]".
  • Loading branch information
jnthn committed Mar 5, 2015
1 parent d3ba345 commit bbe6949
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions src/Perl6/Metamodel/ParametricRoleGroupHOW.nqp
Expand Up @@ -38,18 +38,52 @@ class Perl6::Metamodel::ParametricRoleGroupHOW
}

method new_type(:$name!, :$repr) {
# Build and configure the type's basic details.
my $meta := self.new(:selector($selector_creator()));
my $type_obj := self.add_stash(nqp::settypehll(
nqp::newtype($meta, 'Uninstantiable'), 'perl6'));
$meta.set_name($type_obj, $name);
$meta.set_pun_repr($meta, $repr) if $repr;
$meta.set_boolification_mode($type_obj, 5);
$meta.publish_boolification_spec($type_obj);

# We use 6model parametrics to make this a parametric type on the
# arguments we curry with. This means we'll make the curries unique.
nqp::setparameterizer($type_obj, sub ($type, @packed) {
$type.HOW.'!produce_parameterization'($type, @packed);
});

$type_obj
}

method parameterize($obj, *@pos_args, *%named_args) {
my $curried := $currier.new_type($obj, |@pos_args, |%named_args);

# We only take positional args into account for the parametric key. If
# there are no nameds, we push this class in place of them so as to make
# an otherwise equal key always the same, and named args make it always
# unequal.
my class NO_NAMEDS { }

method parameterize($obj, *@args, *%named_args) {
my int $i := 0;
my int $n := nqp::elems(@args);
while $i < $n {
@args[$i] := nqp::decont(@args[$i]);
$i++;
}
nqp::push(@args, %named_args || NO_NAMEDS);
nqp::parameterizetype($obj, @args);
}

method !produce_parameterization($obj, @packed) {
my @args := nqp::clone(@packed);
my $maybe_nameds := nqp::pop(@args);
my $curried;
if $maybe_nameds {
my %nameds := $maybe_nameds;
$curried := $currier.new_type($obj, |@args, |%nameds);
}
else {
$curried := $currier.new_type($obj, |@args);
}
$curried.HOW.set_pun_repr($curried, self.pun_repr($obj));
$curried
}
Expand Down

0 comments on commit bbe6949

Please sign in to comment.