Skip to content

Instantly share code, notes, and snippets.

@Soft
Created March 25, 2014 17:41
Show Gist options
  • Save Soft/9767133 to your computer and use it in GitHub Desktop.
Save Soft/9767133 to your computer and use it in GitHub Desktop.
Church numerals
var addOne = function (x) { return x+1; };
var church = function(n) {
if (n === 0) {
return function(fn) {
return function(x) {
return x;
}
}
} else {
return function(fn) {
return function(x) {
return fn(church(n-1)(fn)(x));
}
}
}
};
var unchurch = function(fn) {
return fn(addOne)(0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment