gpt4 book ai didi

scala - 运行 scalaz-stream 的 Process 给出无法找到参数 C : scalaz. Catchable[F2] 的隐式值?

转载 作者:行者123 更新时间:2023-12-01 22:22:25 26 4
gpt4 key购买 nike

为什么我会收到以下信息 error: could not find implicit value for parameter C: scalaz.Catchable[F2]执行P(1,2,3).run时?

[scalaz-stream-sandbox]> console
[info] Starting scala interpreter...
[info]
import scalaz.stream._
import scala.concurrent.duration._
P: scalaz.stream.Process.type = scalaz.stream.Process$@7653f01e
Welcome to Scala version 2.11.0-RC3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0).
Type in expressions to have them evaluated.
Type :help for more information.

scala> P(1,2,3).run
<console>:15: error: could not find implicit value for parameter C: scalaz.Catchable[F2]
P(1,2,3).run
^

The scalaz-stream-sandbox project可在 GitHub 上获取。执行sbt console然后P(1,2,3).run面对这个问题。

最佳答案

当你写Process(1, 2, 3)时,您会得到 Process[Nothing, Int] ,这是一个不知道它可以发出外部请求的特定上下文的进程 - 它只会发出一些东西。这意味着您可以将其视为 Process0 ,例如:

scala> Process(1, 2, 3).toList
res0: List[Int] = List(1, 2, 3)

这也意味着您不能 run不过,因为运行需要“驱动程序”上下文。

Process在其第一个类型参数中是协变的,您可以在对此上下文有更具体类型的情况下使用它:

scala> import scalaz.concurrent.Task
import scalaz.concurrent.Task

scala> (Process(1, 2, 3): Process[Task, Int]).runLog.run
res1: IndexedSeq[Int] = Vector(1, 2, 3)

或者:

scala> Process(1, 2, 3).flatMap(i => Process.fill(3)(i)).runLog.run
res2: IndexedSeq[Int] = Vector(1, 1, 1, 2, 2, 2, 3, 3, 3)

我同意该错误有点令人困惑,但在正常使用中,您通常不会遇到这种情况,因为您将在将其类型修复为类似 Process[Task, Int] 的上下文中使用该进程。 .

关于scala - 运行 scalaz-stream 的 Process 给出无法找到参数 C : scalaz. Catchable[F2] 的隐式值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22923535/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com