[英]could not find implicit value for evidence parameter of type scalaz.Applicative
I'm trying to reduce this code (scalaz 7.0.x, scala 2.10.x): 我正在尝试减少此代码(scalaz 7.0.x,scala 2.10.x):
type Error[+A] = \/[String, A]
type Result[+A] = OptionT[Error, A]
into this: 进入这个:
type Result[+A] = OptionT[({ type λ[+α] = String \/ α })#λ, A]
And I got error "could not find implicit value for evidence parameter of type scalaz.Applicative[Main.Result]" for: 我得到错误“找不到scalaz.Applicative [Main.Result]类型的证据参数的隐含值”:
val result: Result[Int] = 42.point[Result]
Why reduced code doesn't look like the first example for scalac? 为什么简化代码看起来不像scalac的第一个例子?
Implicit resolution of lambda types seems broken. lambda类型的隐式解析似乎已经破裂。 Apparently the compiler first desugars the the type and then mismatches on the number of type parameters.
显然,编译器首先去掉类型,然后对类型参数的数量进行不匹配。
A 'simplified' example: 一个'简化'的例子:
Defining a monad and two traits. 定义monad和两个特征。
One
is similar to Either
. One
类似于Either
。 Two
is similar to EitherT
Two
类似于EitherT
trait Monad[F[_]]
trait One[A, B]
object One {
implicit def m[A]: Monad[({ type T[x] = One[A, x] })#T] = ???
}
trait Two[F[_], A]
object Two {
implicit def m[F[_]]: Monad[({ type T[x] = Two[F, x] })#T] = ???
}
Defining a type alias and a case class to partially apply One
with String
as it's first parameter. 定义一个类型别名和一个case类,以部分应用
One
String
作为它的第一个参数。 The case class version can be used as a workaround. 案例类版本可用作变通方法。
type OneX[A] = One[String, A]
case class OneY[A](value: OneX[A])
object OneY {
implicit def m(implicit ev: Monad[OneX]): Monad[OneY] = ???
}
Implicit resolution of all 'simple' types works. 所有“简单”类型的隐式解析都有效。
implicitly[Monad[OneX]]
implicitly[Monad[({ type T[x] = One[String, x] })#T]]
implicitly[Monad[OneY]]
Defining several type aliases that partially apply Two
定义部分应用
Two
几个类型别名
type TwoX[A] = Two[OneX, A]
type TwoY[A] = Two[({ type T[x] = One[String, x] })#T, A]
type TwoZ[A] = Two[OneY, A]
Here we see that the one using the lambda type fails. 在这里我们看到使用lambda类型的那个失败了。
implicitly[Monad[TwoX]]
implicitly[Monad[TwoY]] // fails
implicitly[Monad[TwoZ]]
Here we see that all lambda types that use a type alias fail. 在这里,我们看到使用类型别名的所有lambda类型都失败了。 Only the one that actually refers to a stable type with a single parameter succeeds.
只有实际引用具有单个参数的稳定类型的那个成功。
implicitly[Monad[({ type T[x] = Two[OneX, x] })#T]] // fails
implicitly[Monad[({ type T[x] = Two[OneY, x] })#T]]
implicitly[Monad[({ type T[x] = Two[({ type T[x] = One[String, x] })#T, x] })#T]] //fails
My knowledge about the compiler is fairly limited and this might be related to the bug @TravisBrown points to. 我对编译器的了解相当有限,这可能与@TravisBrown指向的bug有关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.