使用Scala 2.8.1,編譯此:爲什麼Scala使用元組進行表達無法編譯?
val t = (40, 2)
println(for ((i, j) <- List(t)) yield i + j)
val e: Either[String, (Int, Int)] = Right(t)
println(e.right.map {
case (i, j) => i + j
})
println(for ((i, j) <- e.right) yield i + j)
給出了這樣的:
test.scala:9: error: constructor cannot be instantiated to expected type;
found : (T1, T2)
required: Either[Nothing,(Int, Int)]
println(for ((i, j) <- e.right) yield i + j)
根據Scala中編程,所述用於表達應相當於在地圖/情況下表達,但是隻有後者纔會編譯。我做錯了什麼,我該怎麼做?