Created
November 16, 2016 15:02
-
-
Save hamishdickson/43f2b783ef079b929db827efce0f36db 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
scala> trait Foo[T] { | |
| type A | |
| def woozle(a: T): A | |
| } | |
defined trait Foo | |
scala> implicit val bar = new Foo[Int] { | |
| type A = String | |
| def woozle(a: Int): A = s"num: $a" | |
| } | |
bar: Foo[Int]{type A = String} = $anon$1@5af864a7 | |
scala> implicit val baz = new Foo[String] { | |
| type A = Int | |
| def woozle(a: String): A = 0 | |
| } | |
baz: Foo[String]{type A = Int} = $anon$1@833835c | |
scala> def thingy[T](c: T)(implicit F: Foo[T]): F.A = F.woozle(c) | |
thingy: [T](c: T)(implicit F: Foo[T])F.A | |
scala> thingy(1) | |
res3: bar.A = num: 1 | |
scala> thingy("hey") | |
res4: baz.A = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment