jhegedus
jhegedus

Reputation: 20653

Is this a typo in the Scala Language Specification on Parameterized Types?

Should U_i not be rather T_i, as shown in the picture below ?

The same typo (IMHO) is also here.

enter image description here

If it is not a typo, then could someone please tell me where the meaning of T_i is specified ?

Upvotes: 3

Views: 224

Answers (1)

Diego Martinoia
Diego Martinoia

Reputation: 4662

It's not a typo, just a very poor choice of variables and confusion about the scope of their binding :)

In the first paragraph, from "A parametrized" to ", a_n.", the binding of the U_i variables refers to the type parameters, while T is bound to the actual parametric type. For example, say you had

val x : Map[Int, String]

Your T would be Map, your U_1 would be Int and U_2 would be String.

The second paragraph, on the other hand, is completely disconnected from the previous one. Here the type parameters are bound to variables T_1 ... T_n, the parametric type is NOT bound to anything and you have a binding of L_1 ... L_n to the lower bounds of the type parameters and a binding of U_1 ... U_n to the upper bounds of your parameter types.

In this case, had you got (this doesn't compile, it's just for example):

val x : Map[T1 <: AnyRef, T2 >: Int]

Then you'd have your T1, T2 as the actual type parameter, U1 = AnyRef , L2 = Int.

Hope it's clearer now :) (but yeah, poor choice of variables)

To see if you understood, try to guess what U2 and L1 are in the second example. Hint: Look at the type hierarchy of Scala ;)

Upvotes: 3

Related Questions