Created
April 22, 2013 05:21
-
-
Save 9rnsr/1c93f6d6a54318b656b6 to your computer and use it in GitHub Desktop.
After fixing nested struct bugs properly, polymorphic lambda would become implementable easily.
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
struct Lambda(alias func) { | |
//@disable this(); | |
auto ref opCall(A...)(A args) { return func(args); pragma(msg, "tret = ", typeof(func(args)), ", sizeof = ", typeof(func(args)).sizeof); } | |
//void dummy() {} | |
this(int _) { | |
static if (this.tupleof.length) | |
printf("context p = %p\n", this.tupleof[$-1]); | |
} | |
} | |
extern(C) int printf(const char*, ...); | |
void main() | |
{ | |
version(none) | |
{ | |
//auto curry3 = f => a => b => c => f(a, b, c); | |
//auto sum = (a, b, c) => a + b + c; | |
} | |
else version(all) | |
{ | |
auto curry3 = Lambda!( | |
f => | |
Lambda!( | |
a => | |
Lambda!( | |
b => | |
Lambda!( | |
c => | |
f(a, b, c) | |
)(-1/*dummy*/) | |
)(-1/*dummy*/) | |
)(-1/*dummy*/) | |
)(-1/*dummy*/); | |
auto sum = Lambda!((a, b, c) => a + b + c)(-1/*dummy*/); | |
} | |
/+ | |
auto p1 = curry3.tupleof[$-1]; | |
printf("p1 = %p\n", p1); | |
auto f0 = curry3(sum); | |
auto f1 = f0(1); | |
auto f2 = f1(2); | |
auto val = f2(3); | |
+/ | |
auto val = curry3(sum)(1)(2)(3); | |
assert(val == 6); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment