Scala's tuple unwrapping nuance

Posted by Paul Milovanov on Stack Overflow See other posts from Stack Overflow or by Paul Milovanov
Published on 2010-04-28T07:44:44Z Indexed on 2010/04/28 7:53 UTC
Read the original article Hit count: 171

Filed under:
|
|

I've noticed the following behavior in scala when trying to unwrap tuples into vals:

scala> val (A, B, C) = (1, 2, 3)
<console>:5: error: not found: value A
       val (A, B, C) = (1, 2, 3)
            ^
<console>:5: error: not found: value B
       val (A, B, C) = (1, 2, 3)
               ^
<console>:5: error: not found: value C
       val (A, B, C) = (1, 2, 3)
                  ^

scala> val (u, v, w) = (1, 2, 3)
u: Int = 1
v: Int = 2
w: Int = 3

Is that because scala's pattern matching mechanism automatically presumes that all identifiers starting with capitals within patterns are constants, or is that due to some other reason?

Thanks!

© Stack Overflow or respective owner

Related posts about scala

Related posts about tuples