See Original text in context
method type_captures(Parameter: --> List)
Returns a list of variable names of type captures associated with this parameter. Type captures define a type name within the attached code, which is an alias to the type gleaned from the argument during a call.
sub a(::T ::U )a(8); # OUTPUT: «(Int)»say .signature.params[0].type_captures; # OUTPUT: «(T U)»sub b()a(8); # OUTPUT: «Int»
The type used may change from call to call. Once they are defined, type captures can be used wherever you would use a type, even later in the same signature:
sub c(::T , T , ) ;c(4, 5, 6); # OKtry c(4, 5, "six");given $! ;# OUTPUT: «Type check failed in assignment to $zz; expected Int but got Str ("six")»try c("four", 5, "six");given $! ;# OUTPUT: «Type check failed in binding to parameter '$y'; expected Str but got Int (5)»
Type captures may be used at the same time as nominal type constraint.
sub d(::T Numeric , T ) ;d(4, 5); # OKd(4e0, 5e0); # OKtry d(4e0, 5);given $! ;# OUTPUT: «Type check failed in binding to parameter '$y'; expected Num but got Int (5)»try d("four", "five");given $! ;# OUTPUT: «Type check failed in binding to parameter '$x'; expected Numeric but got Str ("four")»