- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Tuple Type / Type Projection
Mon, 2009-06-08, 23:14
scala> trait Test {
| type A <: {type X}
| type B = A#X
| type C = (A)#X
| }
defined trait Test
What does "(A)#X" parse as in the above example? My reading of the language reference suggests it would expand to Tuple1[A]#X and consequently fail to compile, as below.
scala> trait Test1 {
| type A <: {type X}
| type B = Tuple1[A]#X
| }
<console>:6: error: type X is not a member of (Test1.this.A,)
type B = Tuple1[A]#X
| type A <: {type X}
| type B = A#X
| type C = (A)#X
| }
defined trait Test
What does "(A)#X" parse as in the above example? My reading of the language reference suggests it would expand to Tuple1[A]#X and consequently fail to compile, as below.
scala> trait Test1 {
| type A <: {type X}
| type B = Tuple1[A]#X
| }
<console>:6: error: type X is not a member of (Test1.this.A,)
type B = Tuple1[A]#X
So if n=1, the parens are just for grouping. Makes sense, I guess, my confusion is a consequence of the overloaded meaning of parentheses. Perhaps the spec could be updated to be explicit on this point?
-jason
scala> object A { type T = (Int, Int)}
defined module A
scala> var at: A.T = (0, 0)
at: (Int, Int) = (0,0)
scala> object A { type T = (Int)}
defined module A
scala> var at: A.T = 0
at: A.T = 0
scala> object A { type T = ((Int))}
defined module A
scala> var at: A.T = 0
at: A.T = 0
On Tue, Jun 9, 2009 at 12:13 AM, Jason Zaugg <jzaugg@gmail.com> wrote: