This code gives compilation error:
import scala.util.continuations._
object CTest {
def loop: Nothing = reset {
shift {c: (Unit => Nothing) => c()}
loop
}
def main(argv: Array[String]) {loop}
}
Error message:
error: type mismatch;
found : ((Unit) => Nothing) => (Unit) => Nothing
required: ((Unit) => B) => (Unit) => Nothing
But this code works as expected:
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}
}
The question is: why Scala compiler hates me continuations of type Any => Nothing?
loop
is doing what you think it is doing. Try writing() => loop
orloop _
instead. – Daniel C. Sobral Mar 18 '11 at 23:54loop
is to recurse endlessly (and call another methods, but this code is omitted to simplify the example). – E. Verda Mar 19 '11 at 0:21