Skip to content

Instantly share code, notes, and snippets.

@enshahar
Created June 24, 2020 10:54
Show Gist options
  • Save enshahar/4e235b00b3ebe84c4faa5391fe1d901f to your computer and use it in GitHub Desktop.
Save enshahar/4e235b00b3ebe84c4faa5391fe1d901f to your computer and use it in GitHub Desktop.
Fixpoint operator
fun FIX(f: ((Int)->Int)->(Int)->Int): (Int)->Int = { x -> f (FIX(f)) (x) }
val fact_ = { fact: (Int)->Int -> { i: Int -> if(i == 0) 1 else (i * fact (i-1)) } }
val fact = FIX(fact_)
println("factorial(10) = ${fact(10)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment