Вот простой эксперимент в Scala РЕПЛ:Ошибка, более высокие типы Scala: аргументы типа не соответствуют. Тип границы T являются более жесткими, чем тип T заявленное границы
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] = [email protected]
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 Language ?
Другими словами, какие разделы SLS объясняют эти сообщения об ошибках?
Вопрос 2:, как эти сообщения об ошибках можно объяснить в простых терминах (не основаны на СЛС)?
фразировки предыдущий вопрос в словах компилятора:
почему это проблема, которая 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?
Обратите внимания, что вы» re shadowing 'TC' в' Test'. Использование нового имени переменной (например, 'class Test [X [T]]') делает сообщения более четкими. –