fs2 Stream scala 没有隐式类型:Stream.Compiler[Eval,G_]

fs2 Stream scala No implicit of type : Stream.Compiler[Eval,G_]

我正在尝试创建一个 Stream[Eval, String],如下所示:

import cats.Eval
import cats.effect.{ExitCode, IO, IOApp}
import fs2._

object StringEval extends IOApp {

  def evalString: Eval[String] = Eval.always{
      val r = new scala.util.Random(31)
      r.nextString(4)
    }

  override def run(args: List[String]): IO[ExitCode] = {

    Stream
      .eval(evalString)
      .repeat
      .compile
      .lastOrError
      .start
      .as(ExitCode.Success)

  }
}

但问题是我收到编译错误:

Error:(17, 8) could not find implicit value for parameter compiler: fs2.Stream.Compiler[[x]cats.Eval[x],G]
      .compile

我好像没发现错误?我错过了什么?错误指的是什么?

Fs2 Stream.Compiler is not found (could not find implicit value Compiler[[x]F[x],G])

Fs2 Stream#compile now requires a Sync[F]

Eval 没有 Sync 的实例,IO 有。

尝试

def evalString: IO[String] = {
  val r = new scala.util.Random(31)
  Sync[IO].delay(r.nextString(4))
}

Stream
  .eval(evalString)
  .repeat
  .compile
  .lastOrError
  .start
  .as(ExitCode.Success)