尋找一個IO Monad
例如,從Functional Programming in Scala,我創建了一個SBT項目來測試IO.scala
:評估`readLine`在SBT
def ReadLine: IO[String] = IO { readLine }
def PrintLine(msg: String): IO[Unit] = IO { println(msg) }
def converter: IO[Unit] = for {
_ <- PrintLine("Enter a temperature in degrees fahrenheit: ")
d <- ReadLine.map(_.toDouble)
_ <- PrintLine(fahrenheitToCelsius(d).toString)
} yield()
但是,當我運行console
從SBT與REPL訪問上面的類,我想:
scala> val echo = Util.ReadLine.flatMap(Util.PrintLine)
echo: common.I01.IO[Unit] = [email protected]
我期待被提示輸入在文本輸入(通過readLine
),但我看到,我的理解,簡單的匿名函數/類。
我該如何測試上面的代碼?
謝謝。當你說「宇宙的末日是REPL會議」時,你能否詳細說明一下?在幾年前掃描Haskell書籍之前,我曾聽過宇宙術語。 –
我剛剛清理了一下術語,並添加了「宇宙末日」短語的基本原理。讓我知道如果這是明確的。 – mpilquist