预先感谢您的帮助
我有 2 个函数正在尝试通过 Kleisli 箭头编写。这些函数接受字符串并生成 FreeC。kleisli 箭头的创建没有问题,但编译器抱怨它找不到。为简单起见,我将删除一些代码:
import scalaz._
import Scalaz._
import Free.FreeC
import Free._
import Kleisli._
trait AppCompose {
def lift[F[_], G[_], A](fa: F[A])(implicit I: Inject[F, G]): FreeC[G, A] =
Free.liftFC(I.inj(fa))
}
object BigBrother {
sealed trait Sensor[A]
case class Log(log: String) extends Sensor[Unit]
case class Filter(log: String) extends Sensor[String]
case class Secure(log: String) extends Sensor[String]
}
import BigBrother.Sensor
class BigBrother[F[_]](implicit I: Inject[Sensor,F]) extends AppCompose {
import BigBrother._
type FreeString[A] = FreeC[F,String]
def log(log: String) = lift(Log(log))
def filter(log: String) = lift(Filter(log))
def secure(log: String) = lift(Secure(log))
def filterAndSecure(phrase: String) = for {
f <- filter(phrase)
s <- secure(f)
} yield s
// kleisli composition attempt - alternative to filterAndSecure
val fk = kleisli[FreeString, String, String](filter _)
val sk = kleisli[FreeString, String, String](secure _)
val fAndS = fk >=> sk // this is where we have a compilation issue
}
出于某种原因,我得到的是这个编译错误:
could not find implicit value for parameter b: scalaz.Bind[FreeString]
[error] val fAndS = sk >=> fk
感觉应该解决隐含问题,因为 FreeC 在实现 Bind 特征的 monad 实例中,并且我正在通过 import Free._ 导入所有 Free 隐含实例
我在这里想念什么?
先感谢您!