Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
26
Task/Y-combinator/JavaScript/y-combinator-1.js
Normal file
26
Task/Y-combinator/JavaScript/y-combinator-1.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
function Y(f) {
|
||||
var g = f((function(h) {
|
||||
return function() {
|
||||
var g = f(h(h));
|
||||
return g.apply(this, arguments);
|
||||
}
|
||||
})(function(h) {
|
||||
return function() {
|
||||
var g = f(h(h));
|
||||
return g.apply(this, arguments);
|
||||
}
|
||||
}));
|
||||
return g;
|
||||
}
|
||||
|
||||
var fac = Y(function(f) {
|
||||
return function (n) {
|
||||
return n > 1 ? n * f(n - 1) : 1;
|
||||
};
|
||||
});
|
||||
|
||||
var fib = Y(function(f) {
|
||||
return function(n) {
|
||||
return n > 1 ? f(n - 1) + f(n - 2) : n;
|
||||
};
|
||||
});
|
||||
9
Task/Y-combinator/JavaScript/y-combinator-2.js
Normal file
9
Task/Y-combinator/JavaScript/y-combinator-2.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
function Y(f) {
|
||||
return (function(h) {
|
||||
return h(h);
|
||||
})(function(h) {
|
||||
return f(function() {
|
||||
return h(h).apply(this, arguments);
|
||||
});
|
||||
});
|
||||
}
|
||||
17
Task/Y-combinator/JavaScript/y-combinator-3.js
Normal file
17
Task/Y-combinator/JavaScript/y-combinator-3.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
function pseudoY(f) {
|
||||
return (function(h) {
|
||||
return h(h);
|
||||
})(function(h) {
|
||||
return f.bind(function() {
|
||||
return h(h).apply(null, arguments);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var fac = pseudoY(function(n) {
|
||||
return n > 1 ? n * this(n - 1) : 1;
|
||||
});
|
||||
|
||||
var fib = pseudoY(function(n) {
|
||||
return n > 1 ? this(n - 1) + this(n - 2) : n;
|
||||
});
|
||||
5
Task/Y-combinator/JavaScript/y-combinator-4.js
Normal file
5
Task/Y-combinator/JavaScript/y-combinator-4.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
function Y(f) {
|
||||
return function() {
|
||||
return f(Y(f)).apply(this, arguments);
|
||||
};
|
||||
}
|
||||
5
Task/Y-combinator/JavaScript/y-combinator-5.js
Normal file
5
Task/Y-combinator/JavaScript/y-combinator-5.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
function Y(f) {
|
||||
return function() {
|
||||
return f(arguments.callee).apply(this, arguments);
|
||||
};
|
||||
}
|
||||
20
Task/Y-combinator/JavaScript/y-combinator-6.js
Normal file
20
Task/Y-combinator/JavaScript/y-combinator-6.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
let
|
||||
Y= // Except for the η-abstraction necessary for applicative order languages, this is the formal Y combinator.
|
||||
f=>((g=>(f((...x)=>g(g)(...x))))
|
||||
(g=>(f((...x)=>g(g)(...x))))),
|
||||
Y2= // Using β-abstraction to eliminate code repetition.
|
||||
f=>((f=>f(f))
|
||||
(g=>(f((...x)=>g(g)(...x))))),
|
||||
Y3= // Using β-abstraction to separate out the self application combinator δ.
|
||||
((δ=>f=>δ(g=>(f((...x)=>g(g)(...x)))))
|
||||
((f=>f(f)))),
|
||||
fix= // β/η-equivalent fix point combinator. Easier to convert to memoise than the Y combinator.
|
||||
(((f)=>(g)=>(h)=>(f(h)(g(h)))) // The Substitute combinator out of SKI calculus
|
||||
((f)=>(g)=>(...x)=>(f(g(g)))(...x)) // S((S(KS)K)S(S(KS)K))(KI)
|
||||
((f)=>(g)=>(...x)=>(f(g(g)))(...x))),
|
||||
fix2= // β/η-converted form of fix above into a more compact form
|
||||
f=>(f=>f(f))(g=>(...x)=>f(g(g))(...x)),
|
||||
opentailfact= // Open version of the tail call variant of the factorial function
|
||||
fact=>(n,m=1)=>n<2?m:fact(n-1,n*m);
|
||||
tailfact= // Tail call version of factorial function
|
||||
Y(opentailfact);
|
||||
9
Task/Y-combinator/JavaScript/y-combinator-7.js
Normal file
9
Task/Y-combinator/JavaScript/y-combinator-7.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
let
|
||||
polyfix= // A version that takes an array instead of multiple arguments would simply use l instead of (...l) for parameter
|
||||
(...l)=>(
|
||||
(f=>f(f))
|
||||
(g=>l.map(f=>(...x)=>f(...g(g))(...x)))),
|
||||
[even,odd]= // The new destructive assignment syntax for arrays
|
||||
polyfix(
|
||||
(even,odd)=>n=>(n===0)||odd(n-1),
|
||||
(even,odd)=>n=>(n!==0)&&even(n-1));
|
||||
2
Task/Y-combinator/JavaScript/y-combinator-8.js
Normal file
2
Task/Y-combinator/JavaScript/y-combinator-8.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
var Y = f => (x => x(x))(y => f(x => y(y)(x)));
|
||||
var fac = Y(f => n => n > 1 ? n * f(n-1) : 1);
|
||||
Loading…
Add table
Add a link
Reference in a new issue