我正在尝试将Twitter Future与Cats Kleisli 和 Arrow结合起来,但我遇到了一个我不知道如何解决的编译错误。
代码如下:
package com.example
import scala.language.higherKinds
import cats.arrow.Arrow
import cats.implicits._
import cats.data.{EitherT, Kleisli}
import com.twitter.util.Future
object ArrowApp extends App {
type Resp[A] = EitherT[Future, Exception, A]
type KleisliResp[A] = Kleisli[Resp, List[Int], A]
val first: KleisliResp[Int] = Kleisli(_ => EitherT[Future, Exception, Int](Future.value(Right(1))))
val second: KleisliResp[String] = Kleisli(_ => EitherT[Future, Exception, String](Future.value(Right("TEST"))))
def combine[F[_, _] : Arrow, A, B, C](fab: F[A, B], fac: F[A, C]): F[A, (B, C)] = Arrow[F].lift((a: A) => (a, a)) >>> (fab *** fac)
val firstAndSecond: KleisliResp[(Int, String)] = combine(first, second)
}
我得到的错误是:
Error:(20, 31) could not find implicit value for evidence parameter of type cats.arrow.Arrow[[A, B]cats.data.Kleisli[com.example.cats.ArrowApp.Resp,A,B]]
val firstAndSecond: KleisliResp[(Int, String)] = combine(first, second)
如果我用Scala Future替换Twitter Future并导入全局执行器 import scala.concurrent.ExecutionContext.Implicits.global然后代码运行。
我的build.sbt看起来像:
organization := "com.example"
name := "scala-test"
version := "1.0"
scalaVersion := "2.12.3"
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "1.2.0",
"org.typelevel" %% "cats-free" % "1.2.0",
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.0",
"com.twitter" %% "finagle-core" % "18.3.0"
)
scalacOptions ++= Seq("-Ypartial-unification")
resolvers += Resolver.sonatypeRepo("releases")
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.7")
您知道如何修复编译错误吗?
亲切的问候!