在此代码段cleanup_old_logs_service()
中没有进行类型检查。
y.run
编译器显示此错误:
object Test {
type StateStringTask[A] = StateStringT[Task, A]
type StateStringT[M[_], A] = StateT[M, String, A]
val x: Process[Task, Unit] = ???
val y: Process[StateStringTask, Unit] = ???
x.run // This typechecks
y.run // This fails
}
我是否必须为could not find implicit value for parameter C: scalaz.Catchable[[x]Test.StateStringTask[x]]
创建Catchable
个实例?我怎么做?或者在运行StateStringTask
?
答案 0 :(得分:0)
我想这不是最理想的但我通过ThingWithD.__init__()
StateStringTask
的实例来实现它:
Catchable
提升 implicit val stateStringTaskInstance: Catchable[StateStringTask] =
new Catchable[StateStringTask] {
// `a.attempt` stackoverflows, don't ask me why :)
def attempt[A](a: StateStringTask[A]): StateStringTask[Throwable \/ A] = a >>= (
x => Catchable[Task].attempt(Applicative[Task].pure(x)).liftM[StateStringT]
)
def fail[A](err: Throwable) = Catchable[Task].fail(err).liftM[StateStringT]
}
StateT
Process
效果Task
。例如:
def received(queue: Queue[Event]): Process[StateStringTask, Event] = {
val toStateStringTask = new (Task ~> StateStringTask) {
def apply[A](t: Task[A]): StateStringTask[A] = t.liftM[StateStringT]
}
// queue.dequeue: Process[Task, Event]
queue.dequeue.translate(toStateStringTask)
}