Skip to content

Instantly share code, notes, and snippets.

@lukhnos
Created February 8, 2012 18:08
Show Gist options
  • Save lukhnos/1771842 to your computer and use it in GitHub Desktop.
Save lukhnos/1771842 to your computer and use it in GitHub Desktop.
Using Objective-C block to curry a function, take 1
#include <stdio.h>
int f(int x, int y)
{
return x + y;
}
int main()
{
typedef int (^int_to_int_t)(int);
typedef int_to_int_t (^int_to_int_to_int_t)(int);
int_to_int_to_int_t h = ^(int x) {
int_to_int_t g = ^(int y) {
return f(x, y);
};
return g;
};
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