Created
September 19, 2010 13:01
-
-
Save anonymous/586735 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
import scala.util.continuations.{reset,shift,cpsParam} | |
def saveCont[A,B](resetFun : (Unit => A @cpsParam[B,Unit] ) => B @cpsParam[B,Unit]) : A => B = { | |
var mutCC : A => B = null; | |
val switchFun : (Unit => A @cpsParam[B,Unit] )= Unit => { | |
shift{ k : (A => B) => | |
mutCC = k | |
} | |
} | |
reset{ | |
resetFun(switchFun) | |
} | |
val cc = mutCC | |
cc | |
} | |
val cc = saveCont[Int,Int]{switch => | |
val x = 5 + switch() // switch выкидывает из стека, сохраняя его в cc | |
x + 6 | |
} | |
println(cc(5)) // cc(5) продолжает выполнять стек, будто switch() вернуло 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment