Last active
November 16, 2016 15:10
-
-
Save hamishdickson/b86c80c2086ce6dc3538697d683baa74 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"hamish has had $a cakes today" | |
| } | |
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 = hamish has had 1 cakes today | |
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