Skip to content

Instantly share code, notes, and snippets.

@travisbrown
Last active May 24, 2017 21:44
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/476d38774f0ecab9a51f52a9d984a199 to your computer and use it in GitHub Desktop.
Save travisbrown/476d38774f0ecab9a51f52a9d984a199 to your computer and use it in GitHub Desktop.
sealed trait Foo[F[_], A]
case class Bar[F[_], A](f: F[A]) extends Foo[F, A]
case class Baz[F[_], A](f: F[A]) extends Foo[F, String]
sealed trait Qux[F[_], A] {
def value: F[A]
def stuff: F[String]
}
trait Arr[F[_], G[_]] {
def apply[A](f: F[A]): G[A]
}
object Test {
/**
* Compiles on 2.11.8 but not 2.11.11 or 2.12.0-2.
*/
def test1[F[_], G[x] <: Qux[F, x]]: Arr[({ type L[x] = Foo[G, x] })#L, F] =
new Arr[({ type L[x] = Foo[G, x] })#L, F] {
def apply[A](foo: Foo[G, A]): F[A] = foo match {
case Bar(f) => f.value
case Baz(f) => f.stuff
}
}
class Hack[F[_], G[x] <: Qux[F, x]] {
def apply[A](foo: Foo[G, A]): F[A] = foo match {
case Bar(f) => f.value
case Baz(f) => f.stuff
}
}
/**
* Compiles on 2.11.8, 2.11.11, and 2.12.0-2.
*/
def test2[F[_], G[x] <: Qux[F, x]]: Arr[({ type L[x] = Foo[G, x] })#L, F] =
new Arr[({ type L[x] = Foo[G, x] })#L, F] {
def apply[A](foo: Foo[G, A]): F[A] = new Hack[F, G].apply(foo)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment