Skip to content

Instantly share code, notes, and snippets.

@cedric-vincent
Created December 11, 2012 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cedric-vincent/4257198 to your computer and use it in GitHub Desktop.
Save cedric-vincent/4257198 to your computer and use it in GitHub Desktop.
role R { };
my $x = 4 but R;
my $y = 2 but R;
multi sub foo ($a, $b) { say "foo without constraint" }
multi sub foo ($a where { .defined and .does(R) },
$b where { .defined and .does(R) }) {
say "foo with constraints"
}
multi sub infix:<cmp> ($a where { .defined and .does(R) },
$b where { .defined and .does(R) }) {
say "cmp with constraints"
}
foo($x, $y);
$x cmp $y;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment