Skip to content

Instantly share code, notes, and snippets.

@yutaono
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutaono/6c3ef9932dd014ebdab0 to your computer and use it in GitHub Desktop.
Save yutaono/6c3ef9932dd014ebdab0 to your computer and use it in GitHub Desktop.
scala> class A[M[_]]
warning: there was one feature warning; re-run with -feature for details
defined class A
scala> class B[M[+_]]
warning: there was one feature warning; re-run with -feature for details
defined class B
scala> class C[M[-_]]
warning: there was one feature warning; re-run with -feature for details
defined class C
///////////////////////////////////////////////////////
scala> trait X[T]
defined trait X
scala> trait Y[+T]
defined trait Y
scala> trait Z[-T]
defined trait Z
///////////////////////////////////////////////
scala> new A[X]
res12: A[X] = A@2b0c189b
scala> new A[Y]
res13: A[Y] = A@333038c7
scala> new A[Z]
res14: A[Z] = A@75dd085d
////////////////////////////////////////////////
scala> new B[X]
<console>:9: error: kinds of the type arguments (X) do not conform to the expected kinds of the type parameters (type M) in class B.
X's type parameters do not match type M's expected parameters:
type T is invariant, but type _ is declared covariant
val res18 =
^
<console>:10: error: kinds of the type arguments (X) do not conform to the expected kinds of the type parameters (type M) in class B.
X's type parameters do not match type M's expected parameters:
type T is invariant, but type _ is declared covariant
new B[X]
^
scala> new B[Y]
res19: B[Y] = B@1a5c786a
scala> new B[Z]
<console>:9: error: kinds of the type arguments (Z) do not conform to the expected kinds of the type parameters (type M) in class B.
Z's type parameters do not match type M's expected parameters:
type T is contravariant, but type _ is declared covariant
val res20 =
^
<console>:10: error: kinds of the type arguments (Z) do not conform to the expected kinds of the type parameters (type M) in class B.
Z's type parameters do not match type M's expected parameters:
type T is contravariant, but type _ is declared covariant
new B[Z]
^
///////////////////////////////////////////////////////////
scala> new C[X]
<console>:9: error: kinds of the type arguments (X) do not conform to the expected kinds of the type parameters (type M) in class C.
X's type parameters do not match type M's expected parameters:
type T is invariant, but type _ is declared contravariant
val res21 =
^
<console>:10: error: kinds of the type arguments (X) do not conform to the expected kinds of the type parameters (type M) in class C.
X's type parameters do not match type M's expected parameters:
type T is invariant, but type _ is declared contravariant
new C[X]
^
scala> new C[Y]
<console>:9: error: kinds of the type arguments (Y) do not conform to the expected kinds of the type parameters (type M) in class C.
Y's type parameters do not match type M's expected parameters:
type T is covariant, but type _ is declared contravariant
val res22 =
^
<console>:10: error: kinds of the type arguments (Y) do not conform to the expected kinds of the type parameters (type M) in class C.
Y's type parameters do not match type M's expected parameters:
type T is covariant, but type _ is declared contravariant
new C[Y]
^
scala> new C[Z]
res23: C[Z] = C@3ffe9d93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment