pbdirect
pbdirect copied to clipboard
Can't infer PBWriter for recursive Coproducts
For example I want infer pbdirect
instances for the following sealed trait:
import pbdirect._
sealed trait MyList
case class Cons(i: Int, l: MyList) extends MyList
case object Nil extends MyList
PBWriter[MyList] // error: could not find implicit value for evidence parameter of type pbdirect.PBWriter[MyList]
PBReader[MyList] // ok
PBReader
is inferred just fine, but PBWriter
is not.
My guess is that it should be tail: Lazy[PBWriter[T]]
in implicit def cconsWriter
instead of just tail: PBWriter[T]
implicit def cconsWriter[H, T <: Coproduct](
implicit head: PBWriter[H],
tail: PBWriter[T]): PBWriter[H :+: T] // it should be Lazy[PBWriter[T]]
just as it's implemented for PBReader
implicit def cconsParser[H, T <: Coproduct](
implicit
head: PBParser[H],
tail: Lazy[PBParser[T]]): PBParser[H :+: T]