Adam Rabung
Adam Rabung

Reputation: 5224

What exactly did Scala improve with pattern matching in 2.10?

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?

Upvotes: 26

Views: 1298

Answers (2)

Daniel C. Sobral
Daniel C. Sobral

Reputation: 297205

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.

Upvotes: 10

oxbow_lakes
oxbow_lakes

Reputation: 134270

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

Upvotes: 16

Related Questions