Created
December 3, 2011 02:59
-
-
Save colomon/1425858 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub trait_mod:<is>(Routine $r, :$symmetric!) { | |
sub gen(::T2, ::T1) { | |
(sub (T1 $a, T2 $b) { say "woah"; $r($b, $a) }).instantiate_generic(nqp::hash('T1', T1, 'T2', T2)); | |
}; | |
my @params = $r.signature.params; | |
die "symmetric only works on binary functions" unless @params == 2; | |
gen(@params[0].type, @params[1].type); | |
} | |
multi sub foo(Int $a, Str $b) is symmetric { | |
say $b x $a; | |
} | |
foo(10, "Hello"); # works | |
foo("Hello", 10); # results in | |
# Calling 'foo' will never work with argument types (str, int) (line 18) | |
# Expected any of: | |
# :(Int $a, Str $b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment