3 ms·
You really can build everything out of anonymous functions, including all of arithmetic: zero = function(x,y){ return y; } succ = function (f) { return
by freyrs3 16y ago
You really can build everything out of anonymous functions, including all of arithmetic:
zero = function(x,y){ return y; }
succ = function (f) { return function (x) {return f(n(f(x)));};}
one = succ(zero);
two = succ(one);
Look up lambda calculus if anyone is interested.
- jules 16y agoThe only problem then is, how do you do pred the inverse of succ? ;)
- mathgladiator 16y agoThe same way you build the integers. Built it out of pairs. a --> (a,0) -a --> (0,a) succ((a,0)) = (a+1,0) pred((a,0)) = (a,0+1)
- mathgladiator 16y agovia something like: http://news.ycombinator.com/item?id=2030649 http://news.ycombinator.com/item?id=2030649
- freyrs3 16y agoYou need to construct integers with a tuple type, in lambda calculus its: pair = λ x. λ y. λ z. x. y. z Or if you are willing to let pred(0) = 0 then you can use: pred = λ x. λy. λ z. x . (λ i. λ j. j. i. y (λ k. z) (λ k. k)