The method doesNotCompile
accepts only HLists that contain only Label[A]
entries. There is a Mapper that transforms a Label[A] to a String (to be precise: Const[String]#λ
).
However when I apply the mapper, the return type is ev1.Out. I know that's actually an HList of only Strings, but how can I convince the compiler?
import shapeless._
import shapeless.poly._
import shapeless.ops.hlist._
import shapeless.UnaryTCConstraint._
object Util {
case class Label[A](name: String, value: A)
object GetLabelName extends (Label ~> Const[String]#λ) {
def apply[A](label: Label[A]) = label.name
}
}
object Main {
import Util._
def bar(l: List[String]) = ???
def compiles = {
val names = "a" :: "b" :: HNil
bar(names.toList)
}
// A is an HList whose members are all Label[_]
def doesNotCompile[A <: HList : *->*[Label]#λ](labels: A)(
implicit ev1: Mapper[GetLabelName.type, A]) = {
// implicit ev1: Mapper[String, A]) = {
val names = labels map GetLabelName
// names is of type `ev1.Out` - I want it to be an HList of Strings
bar(names.toList)
// error: could not find implicit value for parameter toTraversableAux:
// shapeless.ops.hlist.ToTraversable.Aux[ev1.Out,List,Lub]
}
}
Here is the full gist incl. build.sbt - download and run sbt compile
: https://gist.github.com/mpollmeier/6c53e375d88a32016250