Given a typeclass Printer
with a dependent type Show[A]
:
trait Printer {
type Show[A]
def show[A](x: A)(implicit z: Show[A]): String
}
object Printer {
// the intent here is this is the dumb fallback
// and a user can have a better alternative in scope
implicit val dumbPrinter: Printer = new Printer {
type Show[A] = DummyImplicit
def show[A](x: A)(implicit z: DummyImplicit): String = x.toString
}
}
How do I encode this method:
def r[A](x: A)(implicit printer: Printer, show: printer.Show[A]): String =
printer.show(x)(show)
I've been trying to adapt the working code in @MilesSabin's gist https://gist.github.com/milessabin/cadd73b7756fe4097ca0 and @TravisBrown's blog post https://meta.plasm.us/posts/2015/07/11/roll-your-own-scala/, but I can't find an encoding that works.