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
你能解釋爲什麼會發生這種情況嗎?
這很有趣。感謝您的回覆。 –