Created
March 19, 2018 20:52
-
-
Save roberthoenig/68fb3e73d238aa432455499775ec6a4b to your computer and use it in GitHub Desktop.
Julia implementation of a Y combinator, together with an exmplae implementation of factorials.
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
# Define a strict Y combinator function. | |
Y = (f) -> ((x)->(f((y)->((x(x))(y)))))( | |
(x)->(f((y)->((x(x))(y)))) | |
) | |
# Use the Y combinator the implement a factorial function. | |
factorialbasefunc = (f) -> ((n)->(n==0 ? 1 : n*f(n-1))) | |
factorial = Y(factorialbasefunc) | |
println(factorial(5)) # 120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment