Guest User

Untitled

a guest
May 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. case class Hoge()
  2. case class Foo()
  3. case class Dummy()
  4.  
  5. trait C[A, Conv] {
  6. def method(a: A): Conv
  7. }
  8.  
  9. trait Show[A] { def format(a: A): String }
  10.  
  11. object InstanceDeclarations {
  12. implicit object HogeInstance extends C[Hoge, String] {
  13. def method(a: Hoge): String = "Hoge"
  14. }
  15. implicit object FooInstance extends C[Foo, Dummy] {
  16. def method(a: Foo): Dummy = Dummy()
  17. }
  18. implicit object ShowString extends Show[String] {
  19. def format(a: String): String = a
  20. }
  21. }
  22.  
  23. import InstanceDeclarations._
  24.  
  25. object ConstraintsOnAssociativeType {
  26. def func[S, Conv](s: S)(implicit cs: C[S, Conv], show: Show[Conv]): String = show.format(cs.method(s))
  27. println(func(Hoge()))
  28. //println(func(Foo()))
  29. }
Add Comment
Please, Sign In to add comment