Skip to content

Instantly share code, notes, and snippets.

@xevix
Created January 8, 2016 14:20
Show Gist options
  • Save xevix/0bb6dcac184e8f5d6659 to your computer and use it in GitHub Desktop.
Save xevix/0bb6dcac184e8f5d6659 to your computer and use it in GitHub Desktop.
Coproduct Scala Worksheet Fail
// From Shapeless `coproduct.scala`
sealed trait Animal
case class Cat(name: String, livesLeft: Int) extends Animal
case class Dog(name: String, bonesBuried: Int) extends Animal
case class Koala(name: String, leavesEaten: Int) extends Animal
case class Sloth(name: String, daysToClimbDownFromCurrentTree: Int) extends Animal
val garfield = Cat("Garfield", 9)
val odie = Dog("Odie", 3)
val koala = Koala("foo", 10)
val sloth = Sloth("bar", 2)
// NOTE: This line fails in worksheet, as it can't find the implicit based on the `Animal` type, but works from console
val genAnimal = Generic[Animal]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment