2017-03-20 226 views
0

轉換教程,正在運行的程序,我想在這裏的教程轉換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") 

回答

0

埃德蒙·諾布爾回答我的問題在這裏:https://github.com/atnos-org/eff/issues/80#issuecomment-287667353

的IntelliJ爲什麼不能找出你的代碼的原因特別看起來是因爲IntelliJ不能模擬隱式導向類型推斷;成員暗示有一個類型成員Out,它們代表剩餘效果堆棧。如果IDE無法計算出它,它會在一個新的類型變量中執行,因此不能調用run ops構造函數,因爲根據IntelliJ的推斷類型是Eff[m.Out, A]而不是Eff[NoFx, A]

FIX:我能單獨編譯文件,然後運行它,即使錯誤是在IDE仍然突出。

除非IntelliJ IDEA中有一些我沒有啓用的功能,這看起來像是IntelliJ IDEA中的一個限制和/或錯誤。