Skip to content

Instantly share code, notes, and snippets.

@bseibold
Created December 29, 2010 15:36
Show Gist options
  • Save bseibold/758638 to your computer and use it in GitHub Desktop.
Save bseibold/758638 to your computer and use it in GitHub Desktop.
reimplementation of scala.util.control.Breaks using Scala 2.8 Continuations
trait Breaks {
import scala.util.continuations.{reset,shift}
def breakable = reset[Unit,Unit] _
def break = shift { k: (Unit => Unit) => () }
}
object CPSBreaks extends Application with Breaks {
breakable {
println("1")
breakable {
println("2")
break
println("3")
}
println("4")
break
println("5")
}
}
@bseibold
Copy link
Author

compile with scalac -P:continuations:enable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment