Вот простой эксперимент в Scala REPL:
scala> trait A; trait B extends A; trait C extends B
defined trait A
defined trait B
defined trait C
scala> trait TC[T]
defined trait TC
scala> trait TC2[T <: B]
defined trait TC2
scala> class Test[TC[T]]
warning: there was one feature warning; re-run with -feature for details
defined class Test
scala> new Test[TC]
res1: Test[TC] = Test@6f195bc3
scala> new Test[TC2]
<console>:11: error: kinds of the type arguments (TC2) do not conform to the expected kinds of the type parameters (type TC) in class Test.
TC2's type parameters do not match type TC's expected parameters:
type T (in trait TC2)'s bounds <: B are stricter than type T's declared bounds >: Nothing <: Any
val res2 =
^
<console>:12: error: kinds of the type arguments (TC2) do not conform to the expected kinds of the type parameters (type TC) in class Test.
TC2's type parameters do not match type TC's expected parameters:
type T (in trait TC2)'s bounds <: B are stricter than type T's declared bounds >: Nothing <: Any
new Test[TC2]
^
Вопрос 1:
Как можно объяснить эти сообщения об ошибках на основе Спецификации языка Scala?
Другими словами, какие разделы SLS объясняют эти сообщения об ошибках?
Вопрос 2: как объяснить эти сообщения об ошибках простыми терминами (не основанными на SLS)?
Формулируя предыдущий вопрос словами компилятора:
почему проблема в том, что TC2's type parameters do not match type TC's expected parameters
, то есть type T (in trait TC2)'s bounds <: B are stricter than type T's declared bounds >: Nothing
?
Есть ли какая-нибудь книга или статья, в которой объясняется причина этого сообщения об ошибке?
Возможно, где-то в книге Пирса TAPL?
TC
вTest
. Использование нового имени переменной (например,class Test[X[T]]
) делает сообщения более четкими. - person Travis Brown   schedule 06.01.2015