Hi gurus,
after looking at the documentation on Sub, Signature and the raku type
system I find myself unable to constrain the types of functions in the
way I think I need.
The situation: I have a function, let's call in 'walker', whose first
parameter is a callback.
I wish to express that only callbacks with a certain Signature and
return type are acceptable.
Let's say the callback should follow :(Numeric $n --> Numeric). My
callback is going to be more complicated, but for simplicity sake.
I was hoping to be able to use a named type of function with this
signature.
I know I can say
my $sig = :(Numeric $n --> Numeric);
but my attempts to use $sig fail. I found no example of an application
beyond smartmatching.
What I tried so far:
sub walker(&num2num:$sig, ...) { ... }
is syntactically incorrect and yields:
Can only use the : invocant marker in the signature for a method
and only takes a single step in the direction of a more abstract
solution.
I know I can say
sub walker(&num2num:(Numeric $n --> Numeric), ...) { ... }
but I was hoping for an explicit type, maybe using class, or subset or
roles.
I hope to say soemething like
sub walker(Walkable &callback, ...)
What am I missing here?
Thanks,
--
Theo van den Heuvel
Van den Heuvel HLT Consultancy