0
我正在阅读从here斯卡拉延续博客文章。不幸的是,这并不在斯卡拉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
你能解释为什么会发生这种情况吗?
这很有趣。感谢您的回复。 –