我正在从这里阅读 scala 延续博客文章。不幸的是,这在 scala 2.10.0 上不起作用:
def f():Int @cps[Int,Int] = {shift { (k:Int=>Int) => k(6) } - 1}
<console>:10: error: wrong number of type arguments for util.continuations.cps, should be 1
def f():Int @cps[Int,Int] = {shift { (k:Int=>Int) => k(6) } - 1}
^
<console>:10: error: type mismatch;
found : Int @scala.util.continuations.cpsSynth
@scala.util.continuations.cpsParam[Int,Int]
required: Int
def f():Int @cps[Int,Int] = {shift { (k:Int=>Int) => k(6) } - 1}
如果我尝试了建议的类型,同样的交易:
def f():Int @cpsParam[Int,Int] = {shift { (k:Int=>Int) => k(6) } - 1}
<console>:4: error: type mismatch;
found : Int @scala.util.continuations.cpsSynth
@scala.util.continuations.cpsParam[Int,Int]
required: Int
object $eval {
如果我添加一个未使用的输入参数,它不会抱怨:
def f2(x:Int):Int @cpsParam[Int, Int=>Int] = shift { (k:Int=>Int) => k } -1
f2: (x: Int)Int @scala.util.continuations.cpsParam[Int,Int => Int]
reset(f2(1))(0)
res12: Int = -1
你能解释为什么会这样吗?