Created
February 17, 2016 11:59
-
-
Save lrytz/ec4da087dc65e421eb7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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