Skip to content

Instantly share code, notes, and snippets.

@lrytz
Created February 17, 2016 11:59
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 lrytz/ec4da087dc65e421eb7d to your computer and use it in GitHub Desktop.
Save lrytz/ec4da087dc65e421eb7d to your computer and use it in GitHub Desktop.
abstract class A[T, R]{ def apply(x: T): R }
val x: A[Int, Int] = x => x + 1
val x: A[Int, Int] = (x: Int) => x + 1
val x: A[String, Int] = (x: String) => 1
val x: A[String, Int] = (x: Object) => 1
val x: A[Object, Int] = (x: String) => 1 // error expected
object O {
def m(a: A[Int, Int]) = 0
def m(a: Int => Int) = 1
}
O.m(x => x) // needs param type
O.m((x: Int) => x) // function type takes precedence
object O {
def m(a: A[Int, Int]) = 0
def m(f: (Int, Int) => Int) = 1
}
O.m(x => x)
O.m((x, y) => x)
object O {
class Ev
implicit object E1 extends Ev
implicit object E2 extends Ev
def m(a: A[Int, Int])(implicit ol: E1.type) = 0
def m(a: A[String, Int])(implicit ol: E2.type) = 1
}
O.m((x: Int) => 1)
O.m((x: String) => 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment