# New Ticket Created by Benjamin Goldberg # Please include the string: [perl #131511] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org/Ticket/Display.html?id=131511 >
With the current version of rakudo, if I were to run the code “my &foo ();”, I would get the error “Signatures as constraints on variables not yet implemented.” To bring us a little closer to being able to implement this, I propose the following: First, provide a subtype (subrole?) of the Callable role, which has a signature. These subrole would probably be created by writing Callable[:(...)]. Second this paramaterized version of Callable would need to be somewhere in the ancestry of every existing Block, Routine, Sub, Method, Submethod and Macro objects, or at least, for those which have a signature. Third, make "my &varname (blah) ;" become nearly the same as "my Callable[:(blah)] $varname;" except of course for the sigil. Fourth, ensure that paramaterization of Callable *doesn't* produce a separate, distinct role for every signature passed in, but caches based on a canonicalized version of the signature. For now, canonicalization of a signature simply means removing the names of positional parameters, so :(Int $foo) is transformed into :(Int $) These four changes together mean that a user can write: constant two_ints_sub_t = Callable[:(Int $asdf, Int $qwerty -->Int)]; my two_ints_sub_t $foo = sub add (Int $lhs, Int $rhs --> Int) { $lhs+$rhs }; my (Int $x, Int $y --> Int) &bar; say $foo.VAR.WHAT; # "(Callable[:(Int $, Int $-->Int)])" say &bar.VAR.WHAT; # "(Callable[:(Int $, Int $-->Int)])" say $foo.VAR.WHAT === &bar.VAR.WHAT; # "True" A fifth step, adding a method named sub_signature to the paramaterized role, which returns the captured signature, would make it NativeCall friendly. The drawback of this proposal is that it only works with signatures which don't differ other than parameter names. But at least it's a start.