Why is Scala not a monad?

I am interested to learn about design decisions, why scala.Eitherit was not executed as a monad. There is already some discussion of how to bias correctly Either, for example:

But too many details are mentioned, and I could not get a complete overview of why this is done the way it is done. Can someone give an overview of the benefits of having a right-handed bias Either, about the problems for this and the benefits of not having a right-handed bias Either(if they exist at all)?

+5
source share
2 answers

, . Either - , , Either. , Right Left , . adelbertc, scalaz Validation, .

POLA , :

def foo(): Either[Int, Int] = Right(1)
def bar(j: Int): Either[Int, Int] = Left(1)
def baz(z: Int): Either[Int, Int] = Right(3)

// Result is Left(1) 
for (a <- foo().right; b <- bar(a).right; c <- baz(b).right) yield c

, .right for. Left(1) in bar - , , , Either Right -biased. .right :

for (a <- foo(); b <- bar(a); c <- baz(b)) yield c

Either , " ", (1) , , (2), Left(1) , , baz.

Validation, Either .

+7

, , . Scala, for , , . , ,

for (a <- ma if a > 7; /*...*/) yield /*...*/

, ( , ).

Either ( Either[Unit,B], Left(()) ).

: , , , . : , , , . , , , , Either ( , Scala), , for .

+5

All Articles