所以我有以下代码(执行该tutorial的练习4):
import scala.util.continuations._
object Main {
def times(lst: List[Int]): Int@cps[Int] = lst match {
case Nil => 1
case 0 :: rest => shift{(_: Int=>Int) => 0 } * times(rest)
case first :: rest => first * times(rest)
}
def main(args: Array[String]) {
println(reset{times(List(0 to 1000: _*))})
}
}我正在使用scala 2.10.0编译,得到以下警告:
CWSO.scala:3: warning: expression matchEnd9(x: Int){
x
} is cps-transformed unexpectedly
def times(lst: List[Int]): Int@cps[Int] = lst match {
^
one warning found我写代码的方式有什么问题吗?我应该怎么做才能避免这个警告?代码似乎在做正确的事情(当0是第一个元素时,将数字相乘并提前中止)。
发布于 2013-04-03 16:57:51
这闻起来像是一个bug,并被报道为:https://issues.scala-lang.org/browse/SI-6817
https://stackoverflow.com/questions/15781348
复制相似问题