将教程转换为IntelliJ IDEA中正在运行的程序

时间:2017-03-20 01:48:39

标签: scala intellij-idea

我正在尝试将此处的教程http://atnos-org.github.io/eff/org.atnos.site.Introduction.html转换为 IntelliJ-IDEA 中正在运行的 Scala 程序。代码在命令行REPL中运行,但不在IDE中运行。

我只是将所有代码复制并粘贴到一个文件中,添加了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")

1 个答案:

答案 0 :(得分:0)

Edmund Noble在这里回答了我的问题:https://github.com/atnos-org/eff/issues/80#issuecomment-287667353

  

IntelliJ无法弄清楚你的代码的原因看起来是因为IntelliJ不能模拟隐式定向类型推理; Member隐含在其中有一个类型成员Out,表示剩余的效果堆栈。如果IDE无法弄清楚它,它会包含在一个新的类型变量中,因此无法调用run ops构造函数,因为根据IntelliJ的推断类型是Eff[m.Out, A]而不是Eff[NoFx, A]

FIX :我能够单独编译文件然后运行它,即使错误仍然在IDE中突出显示。

除非IntelliJ IDEA中有某些功能尚未启用,否则这看起来像是IntelliJ IDEA中的限制和/或错误。