Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created May 9, 2010 13:48
Show Gist options
  • Save kmizu/395161 to your computer and use it in GitHub Desktop.
Save kmizu/395161 to your computer and use it in GitHub Desktop.
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