Last active
December 2, 2016 18:46
-
-
Save shesek/3059994 to your computer and use it in GitHub Desktop.
Y combinator
This file contains hidden or 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
# The common one, converted to CoffeeScript | |
y = (f) -> ((y)-> y y) (y) -> f (n) -> (y y) n | |
# My version | |
y = ((y)->y y) (y) -> (f) -> (n) -> (f (y y) f) n | |
fact = y (f) -> (n) -> if n is 0 then 1 else n * f n-1 | |
# And a simpler way, requires a different `fact` that passes itself to itself | |
y = (f) -> (n) -> (f f) n | |
fact = y (f) -> (n) -> if n is 0 then 1 else n * (f f) n-1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment