Created
November 22, 2016 13:20
-
-
Save zoffixznet/5f5e6faf84ac4c141b174aa502fcec4e 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 f(::T $p1, T $p2, ::C){ | |
# $p1 and $p2 are of the same type T, that we don't know yet | |
# C will hold a type we derive from a type object or value | |
my C $closure = $p1 / $p2; | |
return sub(T $p1) { | |
$closure * $p1; | |
} | |
} | |
# The first parameter is Int and so must be the 2nd. | |
# We derive the 3rd type from calling the operator that is used in &f. | |
my &s = f(10, 2, Int.new / Int.new); | |
say s(2); # 10 / 2 * 2 == 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment