Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -4,33 +4,32 @@ typedef int (^Func)(int);
typedef Func (^FuncFunc)(Func);
typedef Func (^RecursiveFunc)(id); // hide recursive typing behind dynamic typing
Func fix (FuncFunc f) {
Func Y(FuncFunc f) {
RecursiveFunc r =
^(id y) {
RecursiveFunc w = y; // cast value back into desired type
return f(^(int x) {
return w(w)(x);
});
};
^(id y) {
RecursiveFunc w = y; // cast value back into desired type
return f(^(int x) {
return w(w)(x);
});
};
return r(r);
}
int main (int argc, const char *argv[]) {
@autoreleasepool {
FuncFunc almost_fac = ^Func(Func f) {
return ^(int n) {
if (n <= 1) return 1;
return n * f(n - 1);
};
};
FuncFunc almost_fib = ^Func(Func f) {
Func fib = Y(^Func(Func f) {
return ^(int n) {
if (n <= 2) return 1;
return f(n - 1) + f(n - 2);
};
};
});
Func fac = Y(^Func(Func f) {
return ^(int n) {
if (n <= 1) return 1;
return n * f(n - 1);
};
});
Func fib = fix(almost_fib);
Func fac = fix(almost_fac);

View file

@ -0,0 +1,5 @@
Func Y(FuncFunc f) {
return ^(int x) {
return f(Y(f))(x);
};
}