Skip to content

Instantly share code, notes, and snippets.

@bkyrlach
Created November 2, 2011 18:59
Show Gist options
  • Save bkyrlach/1334541 to your computer and use it in GitHub Desktop.
Save bkyrlach/1334541 to your computer and use it in GitHub Desktop.
Fixed Point Combinator
//This is as close as I've come thus far, but it cheats. :(
object Combinator {
def main(args:Array[String]):Unit = {
lazy val y:((Int => Int) => (Int => Int)) => (Int => Int) = g => g(y(g))(_)
val error:(Int => Int) = n => throw new java.lang.Exception("OOPS")
val fp:((Int => Int) => (Int => Int)) = f => n => if (n == 0) 1 else n * f(n - 1)
println(y(fp)(10))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment