Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the reason this type parameter syntax doesn't compile?

Say I have:

class Class[CC[A, B]]
class Thing[A, B <: Int]
class Test extends Class[Thing] // compile error here

I get the compiler error:

kinds of the type arguments (cspsolver.Thing) do not conform to the expected kinds of the type parameters (type CC) in class Class. cspsolver.
Thing's type parameters do not match type CC's expected parameters: type C's bounds <: Int are stricter than type B's declared bounds >: Nothing <: Any

However when I modify the code such that it looks like this:

class Class[CC[A, B]]
class Thing[A, B] {
  type B <: Int
}
class Test extends Class[Thing]

it compiles fine. Aren't they both functionally equivalent?

like image 203
eddiemundorapundo Avatar asked Aug 06 '13 06:08

eddiemundorapundo


1 Answers

The reason is given in the compiler message. In Class you expect an unrestricted CC, while Thing has the restriction that the second type argument must be <: Int. One possibility is to add the same constraint to Class as in

class Class[CC[A,B <: Int]]
class Thing[A, B <: Int]
class Test extends Class[Thing]
like image 193
Petr Avatar answered Nov 09 '22 23:11

Petr