Good question ... you were very close :-)
The problem is that although this is obvious to us, the Scala compiler cannot conclude that the concatenation of two HLists from Int is an HList of Int elements. We can help him by pulling the concatenation type into a type variable ( Out , pay attention to using an alias of type Prepend.Aux to restrict this new type variable), and then asking him directly to prove that Out has the required property (requiring proof of the Out form),
import shapeless._ import ops.hlist.Prepend import LUBConstraint._ class Foo[L <: HList: <<:[Int]#λ](val l: L) { def ++[H <: HList: <<:[Int]#λ, Out <: HList](h: H) (implicit prepend: Prepend.Aux[L, H, Out], ev: LUBConstraint[Out, Int]) = { new Foo(l ::: h) } }
source share