Skip to content

Instantly share code, notes, and snippets.

@lukhnos lukhnos/curry2.m
Created Feb 8, 2012

Embed
What would you like to do?
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
You can’t perform that action at this time.