如何在 Scala 中启用延续? [英] How do I enable continuations in Scala?
问题描述
问题说明了一切.
(然而,关于如何访问 shift
和 reset
操作的细节多年来发生了变化.旧的博客条目和 Stack Overflow 的答案可能已经过时了日期信息.)
(Yet, the details of how to get access to the shift
and reset
operations has changed over the years. Old blog entries and Stack Overflow answers may have out of date information.)
另请参见 什么是 Scala 延续以及为什么要使用它们? 讨论了您可能想用 shift 做什么
和 reset
一旦你有了它们.
See also What are Scala continuations and why use them? which talks about what you might want to do with shift
and reset
once you have them.
推荐答案
Scala 2.11
最简单的方法是使用sbt:
The easiest way is to use sbt:
scalaVersion := "2.11.6"
autoCompilerPlugins := true
addCompilerPlugin(
"org.scala-lang.plugins" % "scala-continuations-plugin_2.11.6" % "1.0.2")
libraryDependencies +=
"org.scala-lang.plugins" %% "scala-continuations-library" % "1.0.2"
scalacOptions += "-P:continuations:enable"
在您的代码(或 REPL)中,执行 import scala.util.continuations._
In your code (or the REPL), do import scala.util.continuations._
您现在可以使用 shift
和 reset
来满足您的需求.
You can now use shift
and reset
to your heart's content.
Scala 2.8、2.9、2.10 的历史信息
您必须使用 -P:continuations:enable
标志启动 scala(或 scalac).
You have to start scala (or scalac) with the -P:continuations:enable
flag.
在您的代码中,执行 import scala.util.continuations._
您现在可以使用 shift
和 reset
来满足您的需求.
You can now use shift
and reset
to your heart's content.
如果您使用的是 sbt 0.7,请参阅 https://groups.google.com/forum/#!topic/simple-build-tool/Uj-7zl9n3f4
If you're using sbt 0.7, see https://groups.google.com/forum/#!topic/simple-build-tool/Uj-7zl9n3f4
如果您使用的是 sbt 0.11+,请参阅 https://gist.github.com/1302944
If you're using sbt 0.11+, see https://gist.github.com/1302944
如果您使用的是 maven,请参阅 http://scala-programming-language.1934581.n4.nabble.com/scala-using-continuations-plugin-with-2-8-0-RC1-and-maven-td2065949.html#a2065949
If you're using maven, see http://scala-programming-language.1934581.n4.nabble.com/scala-using-continuations-plugin-with-2-8-0-RC1-and-maven-td2065949.html#a2065949
这篇关于如何在 Scala 中启用延续?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!