Skip to content

Instantly share code, notes, and snippets.

@vvviiimmm
Created June 1, 2019 17:01
Show Gist options
  • Save vvviiimmm/77b3470e63ce9cd281898339f2e72aa6 to your computer and use it in GitHub Desktop.
Save vvviiimmm/77b3470e63ce9cd281898339f2e72aa6 to your computer and use it in GitHub Desktop.
object Main extends App {
def fix[A](f: (=> A) => A): A = {
lazy val a: A = f(a)
a
}
val gac: (=> BigInt => BigInt) => BigInt => BigInt =
fac => n => if (n == 0) 1 else n * fac.apply(n - 1)
val facF =
fix[BigInt => BigInt](fac => n => if (n == 0) 1 else n * fac.apply(n - 1))
val factorial = fix(gac)
println(factorial(1000))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment