Last active
May 3, 2019 09:53
-
-
Save slouc/fd61d394d8251f51fbe697fb872b5afe to your computer and use it in GitHub Desktop.
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
def Y[A](func: (A => A) => (A => A)): (A => A) = | |
func(Y(func))(_) | |
def factorial: Int => Int = | |
Y { | |
(f: Int => Int) => | |
(n: Int) => | |
if (n <= 0) 1 else n * f(n - 1) | |
} | |
println(factorial(5)) // 120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment