I have a type class C
with an extension m
:
trait C[A]:
def ofString(s: String): A
def stringOf(a: A): String
extension (a: A) def m: String = stringOf(a)
def code[A: C]: String =
import scala.language.implicitConversions
given Conversion[String, A] with
def apply(s: String): A = summon[C[A]].ofString(s)
val ev = summon[C[A]]
import ev.m
"Y".m
My question is this: Is there a way to avoid the import ev.m
(and the val ev
altogether)?
Just "Y".m
requires an implicit conversion from String
to A
, followed by an extension on A
, and seems to be too much for the compiler.
(code is here: Scastie - An interactive playground for Scala.)