Skip to content

Instantly share code, notes, and snippets.

@binshuohu
Created November 25, 2015 06:27
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 binshuohu/2a0e7885f724c3466441 to your computer and use it in GitHub Desktop.
Save binshuohu/2a0e7885f724c3466441 to your computer and use it in GitHub Desktop.
test whether implicit evidence needs both covariance and contravariance
object Crap extends App {
sealed abstract class <=<[From, +To] extends (From => To) {
}
implicit def conforms[A]: <=<[A, A] = new <=<[A, A] {
def apply(from: A): A = ???
}
class A[T] {
def foo[U](u: U)(implicit ev: <=<[U, T]) = ()
def bar[U](u: U)(implicit ev: <=<[T, U]) = ()
}
val a = new A[AnyVal]
val x: Any = 12
a.foo(12)
a.bar(x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment