Is this a typo in the Scala language specification for parameterized types?

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

The same typo (IMHO) is also here .

enter image description here

If this is not a typo, can someone tell me where the T_i value is specified?

+3


source to share


1 answer


This is not a typo, just a very bad choice of variables and confusion about their binding :)

In the first paragraph from "A parameterized" to ", a_n." the binding of the U_i variables is related to the type parameters, and the T is bound to the actual parametric type. For example, let's say you had

val x : Map[Int, String]

      

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

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



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

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

      

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

Hopefully this is clearer now :) (but yes, bad choice of variables)

To see if you get it, try to guess that the second example uses U2 and L1. Hint: look at Scala's type hierarchy;)

+3


source







All Articles