我有這個實現scalaz驗證,它似乎是隱式scalaz.Bind不在範圍內,因此表達式不工作。 下面是代碼:驗證:隱式scalaz.Bind未找到
import scalaz._
import Scalaz._
case class User(name: String, knowScala: Boolean, age: Int)
object PublicValidationSpec extends BasicValidation {
def validate(user: User): Validation[String, String] = {
for {
b <- checkAge(user)
c <- checkName(user)
} yield s"Congrats, ${c.name}"
}
}
trait BasicValidation {
def checkName(user: User): Validation[String, User] = {
if(user.name == "") "must have a name".fail else user.success
}
def checkAge(user: User): Validation[String, User] = {
if(user.age < 3) "must be a valid age".fail else user.success
}
}
的例外是
Error:(14, 25) Implicit not found: scalaz.Unapply[scalaz.Bind,
scalaz.Validation[String,scalaz.validation.User]]. Unable to unapply type
`scalaz.Validation[String,scalaz.validation.User]` into a type constructor of
kind `M[_]` that is classified by the type class `scalaz.Bind`. Check that the
type class is defined by compiling `implicitly[scalaz.Bind[type constructor]]` and
review the implicits in object Unapply, which only cover common type 'shapes.'
b <- checkAge(user)
Did i miss some implicit imports here ?
^
什麼版本的scalaz? – drstevens
「org.scalaz」%「scalaz-core_2.10」%「7.1.0-M5」and scala core library is 2.10.2 –
已更新我的回答7.1.0-M5/6 – drstevens