Last active
November 23, 2015 12:36
-
-
Save roberto/f9b67a6ac943ac8752cd to your computer and use it in GitHub Desktop.
Church numerals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "" | |
-- || |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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