Skip to content

Instantly share code, notes, and snippets.

@davegurnell
Last active October 27, 2016 12:58
Show Gist options
  • Select an option

  • Save davegurnell/5c8ffe698c50c0c6b3d9ebfead3063ce to your computer and use it in GitHub Desktop.

Select an option

Save davegurnell/5c8ffe698c50c0c6b3d9ebfead3063ce to your computer and use it in GitHub Desktop.
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