Why isn't Validation a Monad?

后端 未结 2 1745
庸人自扰
庸人自扰 2020-12-02 20:48

an example use case:

def div2(i: Int): Validation[String, Int] = 
    if (i%2 == 0) Validation.success(i/2)
    else Validation.failure(\"odd\")

def div4(i:         


        
相关标签:
2条回答
  • 2020-12-02 21:15

    The issue is that the applicative functor as implied by the monad does not equal the actual applicative functor

    0 讨论(0)
  • 2020-12-02 21:24

    As discussed in the Scalaz group, the problem seems to be that ap would accumulate errors whereas (pseudo-)monadic composition would only operate on the value part of Validation.

    Therefore, one cannot be expressed in terms of the other and thus no monad instance exists for Validation.

    0 讨论(0)
提交回复
热议问题