Why not Monad Validation? (Scalaz7)

usage example:

def div2(i: Int): Validation[String, Int] = if (i%2 == 0) Validation.success(i/2) else Validation.failure("odd") def div4(i: Int) = for { a <- div2(i) b <- div2(a) } yield b 

a mistake . Cannot delete type scalaz.Validation[String,Int] in constructor of type M[_] , which is classified by a class of type scalaz.Bind

I assume the error is caused by the compiler, cannot find the Monad instance for Validation[String, Int]

I can do one for myself, for example:

 object Instances { implicit def validationMonad[E] = new Monad[({type L[A] = Validation[E, A]})#L] { override def point[A](a: => A) = Validation.success(a) override def bind[A, B](fa: Validation[E, A])(f: A => Validation[E, B]) = fa bind f } } 

but why doesn't he have Validation ? after all, Validation already has a bind method.

Also, I can no longer have import Validation._ and import Instances._ (this made me think ...), due to another complex error ...
ambiguous implicit values: something like both validationMonad (my instance) and the ValidationInstances1 method in the attribute ValidationInstances2 ... both correspond to some Functor of Validation ...

should i change the source of scalaz? or am I completely missing something?

please help ~

I am using scalaz 7.0.0-M2

+23
scala monads scalaz scalaz7
Aug 31 '12 at 8:40
source share
2 answers

As discussed in the Scalaz group, the problem is that ap will accumulate errors, while the (pseudo) monadic composition will only work with part of the Validation value.

Therefore, it cannot be expressed in terms of another, and thus, a monad instance does not exist for Validation .

+18
Aug 31 '12 at 9:12
source share

The problem is that the applicative functor implied by the monad is not equal to the actual applicative functor

+5
Aug 31 '12 at 10:00
source share



All Articles