Created
February 8, 2012 18:09
-
-
Save lukhnos/1771845 to your computer and use it in GitHub Desktop.
Using Objective-C block to curry a function, take 2
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
#include <stdio.h> | |
int f(int x, int y) | |
{ | |
return x + y; | |
} | |
int main() | |
{ | |
typedef int (*int_x_int_to_int_t)(int, int); | |
typedef int (^int_to_int_t)(int); | |
typedef int_to_int_t (^int_to_int_to_int_t)(int); | |
typedef int_to_int_to_int_t (^curry_t)(int_x_int_to_int_t); | |
curry_t curry = ^(int_x_int_to_int_t f) { | |
int_to_int_to_int_t h = ^(int x) { | |
int_to_int_t g = ^(int y) { | |
return f(x, y); | |
}; | |
return g; | |
}; | |
return h; | |
}; | |
int_to_int_to_int_t h = curry(f); | |
int_to_int_t g = h(5); | |
int z; | |
z = g(10); | |
printf("%d\n", z); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment