scalarecordshapelesshlist

Cannot find value for implicit parameters (extensible records)


I have a function that looks like the following:

def fun[T <: HList](l: T)(implicit k: HKernelAux[T], ft: FromTraversable[T]) = ???

This function works when I pass an argument of type HList. If I pass an extensible record, which is just a HList with labels, values for the implicit parameters cannot be found. Why is that? Is there a way such that the function works for HLists and extensible records or can I provide another function which works on extensible records?


Solution

  • The thing is that instance of Typeable is not found for FieldType[Witness.`'key`.T, ValueType].

    Try to modify the function:

    import shapeless.{HList, HNil}
    import shapeless.ops.hlist.HKernelAux
    import shapeless.ops.traversable.FromTraversable
    import shapeless.ops.record.Values
    
    def fun[T <: HList, T1 <: HList](l: T)(implicit v: Values.Aux[T, T1], k: HKernelAux[T1],  ft: FromTraversable[T1]) = {
      //use l.values instead of l
    }
    

    Usage:

    import shapeless.syntax.singleton._
    fun('a ->> 1 :: 'b ->> "x" :: HNil) // compiles