Responding to Peter Wolf:
> Then I asked them what type this would yield
>
> for { x <- 1 to 3; y <- 1 to 3 } yield x+y
>
> and the answer was...
>
> res3: scala.collection.immutable.IndexedSeq[Int] = Vector(2, 3, 4, 3, 4,
> 5, 4, 5, 6)
>
> Huh? That not what I thought should happen... I expected a range, or a
> compile error
How could it be a Range? What would start/end/step be for the result in
your example? And what if you replace "x+y" with "(x+y).toString"?
> I thought perhaps Vector extended Range, but this does not compile
>
> def foo(a: Range, b: Range): Range = for { x <- a; y <- b } yield x+y
>
> I thought the whole point of Monads and for comprehension is that the type
> does not change.
Range itself cannot be "monadic", since its element type is fixed - it's
not a type constructor of form M[A].
The "monadic" super type here basically is Traversable. But the Scala
collection API works hard to give you a closer matching type, thus you
end up with IndexedSeq, and the concrete instance happens to be a Vector.
Best regards,
Patrick