轉換教程,正在運行的程序,我想在這裏的教程轉換http://atnos-org.github.io/eff/org.atnos.site.Introduction.html到運行的斯卡拉程序中的IntelliJ-IDEA。代碼在命令行REPL中運行,但不在IDE中運行。在IntelliJ IDEA的
我只是複製和粘貼的所有代碼到一個文件中,增加了一個object Intro extends App
下面是代碼:
class Tutorial{
}
object Intro extends App {
import cats._
import cats.data._
import org.atnos.eff._
type ReaderInt[A] = Reader[Int, A]
type WriterString[A] = Writer[String, A]
type Stack = Fx.fx3[WriterString, ReaderInt, Eval]
import org.atnos.eff.all._
import org.atnos.eff.syntax.all._
// useful type aliases showing that the ReaderInt and the WriterString effects are "members" of R
// note that R could have more effects
type _readerInt[R] = ReaderInt |= R
type _writerString[R] = WriterString |= R
def program[R: _readerInt : _writerString : _eval]: Eff[R, Int] = for {
// get the configuration
n <- ask[R, Int]
// log the current configuration value
_ <- tell("the required power is " + n)
// compute the nth power of 2
a <- delay(math.pow(2, n.toDouble).toInt)
// log the result
_ <- tell("the result is " + a)
} yield a
println(program[Stack].runReader(6).runWriter.runEval.run)
}
編譯器錯誤在最後一行Cannot resolve symbol run
。
這裏是我的build.sbt文件,以下爲庫的說明:
name := "Tutorial"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies += "org.typelevel" %% "cats" % "0.9.0"
libraryDependencies += "org.atnos" %% "eff" % "3.1.0"
// to write types like Reader[String, ?]
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.3")
// to get types like Reader[String, ?] (with more than one type parameter) correctly inferred
// this plugin is not necessary with Scala 2.12
addCompilerPlugin("com.milessabin" % "si2712fix-plugin_2.11.8" % "1.2.0")