Coercing the unspeakable
My wish for typed Supply
would be rather limited if we could not coerce to roles.
role R[::T] {}
class A {
method m(R[Int]() $_) { say $_ ~~ R[Int] }
}
class B {
method R[Int]() {}
}
# OUTPUT: Missing block
at /home/dex/projects/raku/tmp/typed-supply.raku:35
------> method R⏏[Int]() {}
So a Signature
can ask for a coercion to a parametrised role but a class can’t provide such a method because the compiler doesn’t like the name. From the standpoint of the compiler method names are just strings. The class
keyword is just veneer for the MOP.
B.^add_method('R[Int]', method {
class :: does R[Int] {
}.new
});
B.^compose;
A.new.m(B.new);
# OUTPUT: True
Having a dynamic compiler for a dynamic language does come with perks. However, using silly method names is not specced. So a problem solving issue is still in order.
Categories: Raku
It’s easier than that
As specced in S02-names/indirect.t . I’m not sure if this is meant to work like that, thought.