Guest User

Untitled

a guest
Jan 16th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. sealed trait MyType
  2. object Type1 extends MyType
  3. object Type2 extends MyType
  4. case class Type3(i:Int) extends MyType
  5.  
  6. def show[A :< MyType](a: A)(implicit sh: Show[A]) = sh.show(a) // Will not compile
  7.  
  8. implicit val type3CanShow: Show[Type3] =
  9. new Show[Type3] {
  10. def show(t: Type3): String = s"show ${t.i}"
  11. }
  12.  
  13. def show[A :< MyType](a: A)(implicit sh: Show[A]) =
  14. a match {
  15. case t: Type1 => sh.show(t)
  16. case t: Type2 => sh.show(t)
  17. case t: Type3 => sh.show(t)
  18. }
Add Comment
Please, Sign In to add comment