I'm trying to write a factory to create case classes. I'm creating a command line tool that accepts String representations for the parameters of the case class. Anyway the idea being to limit changes for additions to creating an implicit for the new type, but I can't seem to get past the starting line. Below is some code that attempts to create a case object (so no parameters - the most trivial case), but scalac complains that it "cannot find the implicit value for parameter factory". Gotta be something stoopid, but I've tried everything I can think of. If anyone can point me in the right direction, it would be most appreciated. Thanks.
object Message {
case object Person
sealed trait Repr[T] {
def value: T
}
trait Parm0Factory[R] {
def instance(): R
}
implicit val personFactory = new Parm0Factory[Person.type] {
def instance() = Person
}
case class Parm0[R]() extends Repr[R] {
override def value(): R = xform
private def xform(implicit factory: Parm0Factory[R]): R = factory.instance()
}
def main(args: Array[String]): Unit = {
val t1 = Parm0[Person.type]()
println(t1.value)
}
}
You have an implicit definition for
PersonFactory[Person.Type]
, but what yourxform
call is looking for and not finding isPersonFactory[R]
. It is not the same type.