Scala 新手,我刚刚下载了 Eclipse 3.6.2 和Scala IDE 2.0.0-beta4(带有 Scala 2.9.0.final)。我创建了一个新的 Scala 项目来尝试分隔延续:
package delimCCTests
import scala.util.continuations._
object Test extends App {
val result = reset {
1 + shift { k: (Int => Int) => k(k(5)) } + 1
}
println(result)
}
这编译得很好,然后我单击 Run as -> Scala application 并得到这个异常:
Exception in thread "main" java.lang.NoSuchMethodError: scala.util.continuations.package$.shift(Lscala/Function1;)Ljava/lang/Object;
at delimCCTests.Test$$anonfun$1.apply$mcI$sp(DelimCCTests.scala:7)
at delimCCTests.Test$$anonfun$1.apply(DelimCCTests.scala:7)
at delimCCTests.Test$$anonfun$1.apply(DelimCCTests.scala:7)
at scala.util.continuations.package$.reset(package.scala:20)
at delimCCTests.Test$delayedInit$body.apply(DelimCCTests.scala:6)
at scala.Function0$class.apply$mcV$sp(Function0.scala:34)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.App$$anonfun$main$1.apply(App.scala:60)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:30)
at scala.App$class.main(App.scala:60)
at delimCCTests.Test$.main(DelimCCTests.scala:5)
at delimCCTests.Test.main(DelimCCTests.scala)
我究竟做错了什么?我错过了一些配置吗?
顺便说一句,我认为编译器推断出延续的类型?本文使用:
val result = reset {
1 + shift { k => k(k(5)) } + 1
}
但这在我的环境中无法编译...