In the Perl 6 world, currying is an universal term indicating partial instantiation, and it's also used in the world of (parametrized) roles.
However, it's not clear how to actually use it:
role Zipi[::T] {};
class Zape does Zipi[::T] {}
errors with No such symbol T
; same if we use simply T
when declaring the class, but in this case it's Undeclared name
. Eliminating the square brackets and its content yields No appropriate parametric role variant available for 'Zipi'
, same as leaving the square brackets empty. There seems to be a (kinda) bug report going back to 2012, and of course these examples are taken directly from the source code of CurriedRolehow.
Any idea of how this would eventually work or if it's possible to curry parametrized roles by instantiating only some of their parameters?
The
CurriedRoleHOW
meta-class represents a role, let's sayR
, that has been given some set of parameters, for exampleR[Int,Str]
. It's curried in the sense that a role always has an implicit first parameter, which is the class it is eventually composed in to, and so it holds theR
and theInt,Str
arguments, and then injects them at the point that the role is instantiated (composition time).One certainly cannot write:
And expect it to do anything reasonable;
::T
is a type capture, and so can only go in a signature. Here, it is being used as an argument to instantiate a role, and is rightly complained about. Further, aclass
is always a concrete thing, not a generic thing.It is possible for a role to be curried with a type variable for later instantiation, however. Given a role with two type parameters:
We can write another role that fixes one and passes along the other one:
And then use it like this:
Which has the output:
In this example, the
RA[T, Int]
is also modeled by theCurriedRoleHOW
metaclass, except this time it has the holeT
as well as the implicit::?CLASS
, which I believe achieves that you asked for.