daily pastebin goal
89%
SHARE
TWEET

Untitled

a guest May 25th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top