Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case class Hoge()
- case class Foo()
- case class Dummy()
- trait C[A, Conv] {
- def method(a: A): Conv
- }
- trait Show[A] { def format(a: A): String }
- object InstanceDeclarations {
- implicit object HogeInstance extends C[Hoge, String] {
- def method(a: Hoge): String = "Hoge"
- }
- implicit object FooInstance extends C[Foo, Dummy] {
- def method(a: Foo): Dummy = Dummy()
- }
- implicit object ShowString extends Show[String] {
- def format(a: String): String = a
- }
- }
- import InstanceDeclarations._
- object ConstraintsOnAssociativeType {
- def func[S, Conv](s: S)(implicit cs: C[S, Conv], show: Show[Conv]): String = show.format(cs.method(s))
- println(func(Hoge()))
- //println(func(Foo()))
- }
Add Comment
Please, Sign In to add comment