我的印象是 Validation 可以用作 Monoid/SemiGroup 我在 scala 2.9.2 和 scalaz 7 快照下尝试了以下代码
import scalaz._
import Scalaz._
val success1 = 1.success
val success2 = 2.success
val failureA = "A".fail
val failureB = "B".fail
success1 |+| success2
<console>:16: error: diverging implicit expansion for type scalaz.Semigroup[scalaz.Validation[Nothing,Int]]
starting with method validationSemigroup in trait ValidationInstances
success1 |+| success2
^
<console>:16: error: value |+| is not a member of scalaz.Validation[Nothing,Int]
success1 |+| success2
我期待一个Success(3)
然后
failureA |+| failureB
res1: scalaz.Validation[java.lang.String,Nothing] = Failure(AB)
按预期给出
和
success1 |+| failureA
按预期失败
<console>:16: error: diverging implicit expansion for type scalaz.Semigroup[scalaz.Validation[Nothing,Int]]
starting with method validationSemigroup in trait ValidationInstances
success1 |+| failureA
^
<console>:16: error: value |+| is not a member of scalaz.Validation[Nothing,Int]
success1 |+| failureA
为什么|+|
onSuccess
不起作用?这是一个错误还是我在这里错过了什么