2
스칼라 2.8 Continuations-PlugIn을 사용하여 다음과 같은 간단한 생성기를 작성해 봅니다. 다음 오류는 어디서 발생합니까?Continuations와 관련하여 도움이 필요합니다. "비 cps 위치에서 cps 표현을 찾았습니다."
None/None/Some((Unit,Unit))
GenTest.scala:8: error: found cps expression in non-cps position
yieldValue(1)
None/None/Some((Unit,Unit))
GenTest.scala:9: error: found cps expression in non-cps position
yieldValue(2)
None/None/Some((Unit,Unit))
GenTest.scala:10: error: found cps expression in non-cps position
yieldValue(3)
코드 :
import scala.util.continuations._
object GenTest {
val gen = new Generator1[Int] {
yieldValue(1)
yieldValue(2)
yieldValue(3)
}
def main(args: Array[String]): Unit = {
for (v <- gen) {
println(v)
}
}
}
class Generator1[E](gen: => Unit @cps[Unit]) {
var loop: (E => Unit) = null
def foreach(f: => (E => Unit)): Unit = {
loop = f
reset[Unit,Unit](gen)
}
def yieldValue(value: E): Unit @cps[Unit] =
shift { genK: (Unit => Unit) =>
loop(value)
genK(())
()
}
}
감사합니다. 생성자에 대한 by-name-parameters와 관련된 질문을 만들었습니다. http://stackoverflow.com/questions/2647141/by-name-parameters-for-constructors – hotzen
정말 컴파일러에서 허용하지 않는 것 같습니다. stackoverflow를 통해 tiark를 쿼리 할 수 있습니까? – hotzen