Skip to content

Instantly share code, notes, and snippets.

@shesek
Last active December 2, 2016 18:46
Show Gist options
  • Save shesek/3059994 to your computer and use it in GitHub Desktop.
Save shesek/3059994 to your computer and use it in GitHub Desktop.
Y combinator
# 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