Re:Exploring the Peano Axioms Through Algebraic Data Types
by quietbritishjim on Tuesday January 15, 2019 @11:05AM
(#18912111)
Let's try it with x = 2, y = 5:
I agree that your rule would work too though:
Seems more sensible to me, and by adding the same rule to the right hand side we end up only needing a single base case (that 0+0=0)
[ Parent
| on HN ]
Re:Exploring the Peano Axioms Through Algebraic Data Types
by jjaredsimpson on Tuesday January 15, 2019 @07:26PM
(#18917162)
You swapped the order of method arguments though
you are doing x add Sy which isn't the same as Sy add x
Number.prototype.add = function (y) {
var x = Number(this)
return x===0 ? y : (y+1).add(x-1)
}
console.log(Number(3).add(2)) // infinite
Re:Exploring the Peano Axioms Through Algebraic Data Types
by quietbritishjim on Thursday January 17, 2019 @11:47AM
(#18932263)
Oops, sorry, I see what you mean now. You're right, it looks like this is a mistake:
S: innerX => S(y).add(innerX)
It should be S: innerX => S(innerX).add(y)