Created
May 9, 2010 13:48
-
-
Save kmizu/395161 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment