The following code, taken from the excellent Apocalisp blog series: Scala level programming and modified for the implicit parsing script. However, this does not compile with the following message:
error: ambiguous implicit values: both method hParseNil in object HApplyOps of type => (com.mystuff.bigdata.commons.collections.hlist.HNil) => com.mystuff.bigdata.commons.collections.hlist.HNil and method conforms in object Predef of type [A]<:<[A,A] match expected type (com.mystuff.bigdata.commons.collections.hlist.HNil) => com.amadesa.bigdata.commons.collections.hlist.HNil val l = hparse[HNil,HNil](HNil)
Can someone explain why this happens and if it is fixed?
sealed trait HList final case class HCons[H, T <: HList](head: H, tail: T) extends HList { def :+:[T](v: T) = HCons(v, this) } sealed class HNil extends HList { def :+:[T](v: T) = HCons(v, this) } object HNil extends HNil // aliases for building HList types and for pattern matching object HList { type :+:[H, T <: HList] = HCons[H, T] val :+: = HCons } object HApplyOps { import HList.:+: implicit def hParseNil: HNil => HNil = _ => HNil implicit def hParseCons[InH,OutH,TIn <:HList,TOut<:HList](implicit parse:InH=>OutH,parseTail:TIn=>TOut): (InH :+: TIn) => (OutH :+: TOut) = in => HCons(parse(in.head),parseTail(in.tail)) def hparse[In <: HList, Out <: HList](in:In)(implicit parse: In => Out):Out = in } object PG { import HList._ def main(args: Array[String]) { import HApplyOps._ val l = hparse[HNil,HNil](HNil) } }
source share