Skip to content

Instantly share code, notes, and snippets.

@roberto
Last active November 23, 2015 12:36
Show Gist options
  • Save roberto/f9b67a6ac943ac8752cd to your computer and use it in GitHub Desktop.
Save roberto/f9b67a6ac943ac8752cd to your computer and use it in GitHub Desktop.
Church numerals
zero = \s z -> z
one = λs z -> s z
two = λs z -> (s . s) z
arabic = \n -> n + 1
pipes = \n -> n ++ "|"
--two arabic 0
-- 2
--two pipes ""
-- ||
zero = function (next, acc) {
return acc;
}
one = function (next, acc) {
return next(acc);
}
two = function (next, acc) {
return next(next(acc));
}
arabic = function (acc) {
return acc + 1;
}
pipes = function (acc) {
return acc + "|";
}
console.log(two(arabic, 0));
// 2
console.log(two(pipes, ""));
// ||
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment