scala> val a = Need(20)
a: scalaz.Name[Int] = scalaz.Name$$anon$2@173f990
scala> val b = Need(3)
b: scalaz.Name[Int] = scalaz.Name$$anon$2@35201f
scala> for(a0 <- a; b0 <- b) yield a0 + b0
res90: scalaz.Name[Int] = scalaz.Name$$anon$2@16f7209
scala> (a |@| b)
res91: scalaz.ApplicativeBuilder[scalaz.Name,Int,Int] = scalaz.ApplicativeBuilde
r@11219ec
scala> (a |@| b) { _ + _ }
<console>:19: error: ambiguous implicit values:
both method FunctorBindApply in class ApplyLow of type [Z[_]](implicit t: scala
z.Functor[Z], implicit b: scalaz.Bind[Z])scalaz.Apply[Z]
and value nameMonad in object Name of type => scalaz.Monad[scalaz.Name]
match expected type scalaz.Apply[scalaz.Name]
(a |@| b) { _ + _ }
^
Name
是一个Monad
,因此Applicative
也是一个。为什么这段代码不起作用?我是否需要添加任何类型注释才能使其工作?谢谢!