Created
February 5, 2011 21:48
-
-
Save debasishg/812823 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // works for Validation | |
| scala> val a: Validation[String, Int] = 1.success | |
| a: scalaz.Validation[String,Int] = Success(1) | |
| scala> val b: Validation[String, Int] = 2.success | |
| b: scalaz.Validation[String,Int] = Success(2) | |
| scala> val c: Validation[String, Int] = 3.success | |
| c: scalaz.Validation[String,Int] = Success(3) | |
| scala> List(a, b, c) | |
| res6: List[scalaz.Validation[String,Int]] = List(Success(1), Success(2), Success(3)) | |
| scala> res6.sequence[({type λ[α]=Validation[String, α]})#λ, Int] | |
| res8: scalaz.Validation[java.lang.String,List[Int]] = Success(List(1, 2, 3)) | |
| // doesn't work for Either | |
| scala> val x: Either[String, Int] = 1.right | |
| x: Either[String,Int] = Right(1) | |
| scala> val y: Either[String, Int] = 2.right | |
| y: Either[String,Int] = Right(2) | |
| scala> val z: Either[String, Int] = 3.right | |
| z: Either[String,Int] = Right(3) | |
| scala> List(x, y, z) | |
| res9: List[Either[String,Int]] = List(Right(1), Right(2), Right(3)) | |
| scala> res9.sequence[({type λ[α]=Either[String,α]})#λ, Int] | |
| <console>:22: error: could not find implicit value for parameter n: scalaz.Applicative[[α]Either[java.lang.String,α]] | |
| res9.sequence[({type λ[α]=Either[String,α]})#λ, Int] | |
| ^ |
Author
Yes .. I am using 6.0-SNAPSHOT .. Thanks for the clarification ..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I assume you're using Scalaz 6.0-SNAPSHOT.
Unfortunately you need to import
Monad._-- the implicit search forApplicative[X]doesn't include the companion objects of sub-types ofApplicative.scala> import Monad._ import Monad._ scala> res1.sequence[({type λ[α]=Either[String,α]})#λ, Int] res3: Either[java.lang.String,List[Int]] = Right(List(1, 2, 3))