Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sealed trait MyType
- object Type1 extends MyType
- object Type2 extends MyType
- case class Type3(i:Int) extends MyType
- def show[A :< MyType](a: A)(implicit sh: Show[A]) = sh.show(a) // Will not compile
- implicit val type3CanShow: Show[Type3] =
- new Show[Type3] {
- def show(t: Type3): String = s"show ${t.i}"
- }
- def show[A :< MyType](a: A)(implicit sh: Show[A]) =
- a match {
- case t: Type1 => sh.show(t)
- case t: Type2 => sh.show(t)
- case t: Type3 => sh.show(t)
- }
Add Comment
Please, Sign In to add comment