Skip Menu |
Report information
Id: 131511
Status: new
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: ben-goldberg [at]

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)

From: Benjamin Goldberg <ben-goldberg [...]>
Date: Sun, 4 Jun 2017 23:32:35 +0000
Subject: [Feature Request] Take a step closer to Signatures as constraints on variables.
To: rakudobug <rakudobug [...]>
Download (untitled) / with headers
text/plain 1.7k
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.

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at