该代码给出编译错误:斯卡拉:申报时编译错误类型的延续任何=>没有
import scala.util.continuations._
object CTest {
def loop: Nothing = reset {
shift {c: (Unit => Nothing) => c()}
loop
}
def main(argv: Array[String]) {loop}
}
错误消息:
error: type mismatch;
found : ((Unit) => Nothing) => (Unit) => Nothing
required: ((Unit) => B) => (Unit) => Nothing
但这个代码按预期工作:
import scala.util.continuations._
object CTest {
def loop: Nothing = reset {
shift {c: (Unit => Any) => c.asInstanceOf[Unit => Nothing]()}
loop
}
def main(argv: Array[String]) {loop}
}
现在的问题是:为什么Scala编译器不喜欢 me co Any类型的ntinuations => Nothing?
我不知道'loop'是否在做你认为正在做的事。试着写'()=> loop'或'loop _'来代替。 – 2011-03-18 23:54:37
'loop'的唯一目的是无限地递归(并调用另一个方法,但为了简化示例,省略了这段代码)。 – 2011-03-19 00:21:27