Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lukhnos
Created February 8, 2012 18:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukhnos/1771845 to your computer and use it in GitHub Desktop.
Save lukhnos/1771845 to your computer and use it in GitHub Desktop.
Using Objective-C block to curry a function, take 2
#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