-
-
Save teamon/666864 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
object cbfx2 { | |
trait X[K, L] | |
trait A[T] { | |
def foo[L](i: L)(implicit a: X[T, L]) = null | |
} | |
class B[T] extends A[T] | |
object B { | |
implicit def foo[T, L]: X[T, L] = {println("B");null} | |
implicit def foo2[T]: X[T, Int] = {println("B Int");null} | |
} | |
class C extends B[C] | |
object C { | |
implicit def foo[L]: X[C, String] = {println("C");null} | |
} | |
class K { def foo(implicit k: Int) = null } | |
object K { implicit def foo = 0} | |
def main(args: Array[String]) { | |
import K._ | |
val k = new K | |
k.foo | |
val b = new B[B[Int]] | |
b.foo("a") | |
b.foo(3) | |
val c = new C | |
c.foo(3) | |
c.foo("dd") | |
} | |
} |
This file contains hidden or 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
lopex: to jest tzw low priority implicit | |
[22:23] lopex: jesli jest argument implicit i jesli jest wartosc o kompatybilnym do niego typie w singletonie (i singletonach rodzicow) | |
[22:24] lopex: co zostanie zaaplikowany najbardziej precyzyjny | |
[22:24] lopex: czyli | |
[22:24] lopex: c.foo("dd") | |
[22:24] lopex: czyli T jest String | |
[22:25] lopex: er, L | |
[22:25] lopex: to patrzy do singletona C | |
[22:25] lopex: i widzi implicit def foo[L]: X[C, String] | |
[22:26] lopex: kolejna regula to to ze typ implicita musi sie skladac z typu argumentu | |
[22:26] lopex: er, z typ klasy | |
[22:27] lopex: inaczej | |
[22:27] lopex: def foo[L](i: L)(implicit a: X[T, L]) | |
[22:27] lopex: staje sie | |
[22:27] lopex: def foo[L](i: L)(implicit a: X[C, String]) | |
[22:27] lopex: czyli taki jaki jest z object C | |
[22:27] lopex: jasne ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment