Skip to content

Instantly share code, notes, and snippets.

@kaaloo
Created October 8, 2013 20:49
Show Gist options
  • Save kaaloo/6891400 to your computer and use it in GitHub Desktop.
Save kaaloo/6891400 to your computer and use it in GitHub Desktop.
var Zero = {
isZero: function() {
return true;
},
predecessor: function() {
throw "No such element";
},
successor: function() {
return new Succ(this);
},
add: function(that) {
return that;
},
sub: function(that) {
if (that.isZero()) {
return this;
} else {
return predecessor().sub(that.predecessor())
}
}
};
function Succ(n) {
this.n = n;
}
Succ.prototype.isZero = function() {
return false;
}
Succ.prototype.predecessor = function() {
return this.n;
}
Succ.prototype.successor = function() {
return new Succ(this);
}
Succ.prototype.add = function(that) {
new Succ(n.add(that))
}
Succ.prototype.sub = function(that) {
if (that.isZero()) {
return this;
} else {
return predecessor().sub(that.predecessor())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment