Question

I found it interesting that this puzzler, specifically this code:

val (i, j): (Int, Int) = ("3", "4")

Fails at runtime in Scala 2.9.1, but fails at compile time w/ 2.10 M3(which is great). I try to track what's coming in new Scala releases, but I'm unable to connect the dots here. What improvement led to this more precise behavior?

Was it helpful?

Solution

The thing that's going on is that the new pattern matcher is much easier to enhance and maintain, because it's not a rats nest piece of code. The following example code should also exhibit the same change:

("3", "4") match { case (i, j): (Int, Int) => /* whatever */ }

What's happening is Scala understanding at compile time that the pattern can never be matched.

OTHER TIPS

In scala 2.10, the pattern matcher has had a complete re-write and is now the virtualized pattern matcher. Read more about it!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top