Last active
October 27, 2016 12:58
-
-
Save davegurnell/5c8ffe698c50c0c6b3d9ebfead3063ce 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
| import shapeless._ | |
| // Given this poly: | |
| object myPoly extends Poly1 { | |
| implicit val intCase: Case.Aux[Int, Double] = | |
| at[Int](num => num / 2.0) | |
| implicit val stringCase: Case.Aux[String, Int] = | |
| at[String](str => str.length) | |
| } | |
| // This compiles: | |
| object test { | |
| val intResult = myPoly(123) | |
| val stringResult = myPoly("Hello") | |
| val intResult2: Double = intResult | |
| val stringResult2: Int = stringResult | |
| } | |
| // But this doesn't compile: | |
| object test2 { | |
| val intResult: Double = myPoly(123) | |
| val stringResult: Int = myPoly("Hello") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment