Created
June 24, 2020 10:54
-
-
Save enshahar/4e235b00b3ebe84c4faa5391fe1d901f to your computer and use it in GitHub Desktop.
Fixpoint operator
This file contains hidden or 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
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