简体   繁体   English

运行scalaz-stream的Process给出了找不到参数C的隐含值:scalaz.Catchable [F2]?

[英]Running scalaz-stream's Process gives could not find implicit value for parameter C: scalaz.Catchable[F2]?

Why am I getting the following error: could not find implicit value for parameter C: scalaz.Catchable[F2] when executing P(1,2,3).run ? 为什么我收到以下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 is available at GitHub. scalaz-stream-sandbox项目可在GitHub上获得。 Execute sbt console and then P(1,2,3).run to face the issue. 执行sbt console ,然后执行P(1,2,3).run来解决问题。

When you write Process(1, 2, 3) , you get a Process[Nothing, Int] , which is a process that doesn't have any idea about a specific context that it can make external requests against—it's just going to emit some stuff. 当您编写Process(1, 2, 3) ,您将获得一个Process[Nothing, Int] ,这是一个对某个特定上下文没有任何想法的进程,它可以对外部请求进行反对 - 它只会发出一些东西。 This means that you can treat it as a Process0 , for example: 这意味着您可以将其视为Process0 ,例如:

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

It does also mean that you can't run it, though, since run needs a "driver" context. 但这也意味着你无法run它,因为运行需要一个“驱动程序”上下文。

Since Process is covariant in its first type parameter, you can use it in situations where you do have a more specific type for this context: 由于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)

Or: 要么:

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)

I agree that the error is a little confusing, but in normal usage you won't generally run into this situation, since you'll be using the process in a context that will fix its type to something like Process[Task, Int] . 我同意这个错误有点令人困惑,但在正常使用中你通常不会遇到这种情况,因为你将在一个上下文中使用该进程,将其类型修改为Process[Task, Int]

Process0[O]喜欢Process(1, 2, 3)你可以调用.toSource来将它转换为Process[Task, O]runLog.run它或者你可以直接调用toListtoVector等函数得到它的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM