Skip to content

Instantly share code, notes, and snippets.

@travisbrown
Last active August 29, 2015 13:56
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 travisbrown/8893312 to your computer and use it in GitHub Desktop.
Save travisbrown/8893312 to your computer and use it in GitHub Desktop.
import scalaz._, Scalaz._
trait Baz extends Foo {
def r = List(1).liftM[T]
}
scalaVersion := "2.10.3"
libraryDependencies += "org.scalaz" %% "scalaz-core" % "7.0.5"
import scalaz._, Scalaz._
trait Foo {
type T[M[_], A] = ReaderT[M, String, A]
}
trait Bar extends Foo {
def r = List(1).liftM[T]
}
@travisbrown
Copy link
Author

Bar is fine, but Baz crashes with the following error:

[error] /home/travis/tmp/scalaz/baz.scala:7: kinds of the type arguments (Baz.this.T) do not conform to the expected kinds of the type parameters (type G).
[error] Baz.this.T's type parameters do not match type G's expected parameters:
[error] <none>'s bounds<notype> are stricter than type _'s declared bounds >: Nothing <: Any
[error]   def r = List(1).liftM[T]
[error]                        ^
[error] one error found
[error] (compile:compile) Compilation failed

@retronym
Copy link

retronym commented Feb 9, 2014

This has progressed in 2.11, somewhere between: scala/scala@185ff4c...d068b16

% scalac-hash d068b16 -classpath /Users/jason/code/gist/8893312/target/scala-2.11.0-M5/classes:/Users/jason/.ivy2/cache/org.scalaz/scalaz-core_2.11.0-M8/bundles/scalaz-core_2.11.0-M8-7.0.5.jar:/Users/jason/.ivy2/cache/org.scala-lang.modules/scala-parser-combinators_2.11.0-M8/bundles/scala-parser-combinators_2.11.0-M8-1.0.0-RC5.jar:/Users/jason/.ivy2/cache/org.scala-lang.modules/scala-xml_2.11.0-M8/bundles/scala-xml_2.11.0-M8-1.0.0-RC7.jar /Users/jason/code/gist/8893312/baz.scala /Users/jason/code/gist/8893312/foo.scala
/Users/jason/code/gist/8893312/foo.scala:4: error: kinds of the type arguments (M,String,A) do not conform to the expected kinds of the type parameters (type F,type E,type A).
M's type parameters do not match type F's expected parameters:
type _ is invariant, but type _ is declared covariant
  type T[M[_], A] = ReaderT[M, String, A]
                    ^
one error found

% subl foo.scala

% git diff
diff --git a/foo.scala b/foo.scala
index e6e1838..c082847 100644
--- a/foo.scala
+++ b/foo.scala
@@ -1,7 +1,7 @@
 import scalaz._, Scalaz._

 trait Foo {
-  type T[M[_], A] = ReaderT[M, String, A]
+  type T[M[+_], A] = ReaderT[M, String, A]
 }

 trait Bar extends Foo {

% scalac-hash d068b16 -classpath /Users/jason/code/gist/8893312/target/scala-2.11.0-M5/classes:/Users/jason/.ivy2/cache/org.scalaz/scalaz-core_2.11.0-M8/bundles/scalaz-core_2.11.0-M8-7.0.5.jar:/Users/jason/.ivy2/cache/org.scala-lang.modules/scala-parser-combinators_2.11.0-M8/bundles/scala-parser-combinators_2.11.0-M8-1.0.0-RC5.jar:/Users/jason/.ivy2/cache/org.scala-lang.modules/scala-xml_2.11.0-M8/bundles/scala-xml_2.11.0-M8-1.0.0-RC7.jar /Users/jason/code/gist/8893312/baz.scala /Users/jason/code/gist/8893312/foo.scala
warning: there were 1 feature warning(s); re-run with -feature for details
one warning found

With the older compiler (even with the required variance annotation on M):

% scalac-hash 185ff4c -classpath /Users/jason/code/gist/8893312/target/scala-2.11.0-M5/classes:/Users/jason/.ivy2/cache/org.scalaz/scalaz-core_2.11.0-M8/bundles/scalaz-core_2.11.0-M8-7.0.5.jar:/Users/jason/.ivy2/cache/org.scala-lang.modules/scala-parser-combinators_2.11.0-M8/bundles/scala-parser-combinators_2.11.0-M8-1.0.0-RC5.jar:/Users/jason/.ivy2/cache/org.scala-lang.modules/scala-xml_2.11.0-M8/bundles/scala-xml_2.11.0-M8-1.0.0-RC7.jar /Users/jason/code/gist/8893312/baz.scala /Users/jason/code/gist/8893312/foo.scala
/Users/jason/code/gist/8893312/baz.scala:4: error: kinds of the type arguments (Baz.this.T) do not conform to the expected kinds of the type parameters (type G).
Baz.this.T's type parameters do not match type G's expected parameters:
<none>'s bounds<notype> are stricter than type _'s declared bounds >: Nothing <: Any
  def r = List(1).liftM[T]
                       ^
one error found

@retronym
Copy link

retronym commented Feb 9, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment