On 2.7.5.final, I'm attempting to add a Iterable list of Ints like so
def sum(xs: Iterable[Int]): Long = {
var sum = 0L
xs.foreach((x) => sum = sum + x)
sum
}
println(sum(List(1, Integer.MAX_VALUE - 1)))
println(sum(Integer.MAX_VALUE - 1 to Integer.MAX_VALUE))
println(0L + Integer.MAX_VALUE - 1 + Integer.MAX_VALUE)
When I run, I get
2147483647
0
4294967293
And, you might say "use reduceLeft(_ + _)", but it seems to only be able to return the same type as elements in the list... but I want to accumulate to a Long, so I don't have overflow issues.
Update 2009-10-28
This is a bug in Range, as pointed out by Eastsun. It's been reported to the Scala team in ticket 2535