6
假設我有以下代碼:Scala的要麼元組做爲右
val either: Either[String, (Int, Int)] = Right((1,2))
for {
(a, b) <- either.right
} yield a + b
當我評價它在REPL我得到
:13: error: constructor cannot be instantiated to expected type; found : (T1, T2) required: scala.util.Either[Nothing,(Double, Double)] (a, b) <- a.right ^:14: error: not found: value a } yield a + b ^
爲什麼我有這樣的錯誤?我無法從任何一個模式中對元組進行模式匹配?
我正在使用scala 2.10.3。另外爲什麼它有這樣一個奇怪的類型:'用scala.util.Etil產生的可序列化的[String,Int]'?爲什麼不只是'scala.util.E [String,Int]' – maks