1
votes

I am trying to create a hlist implicitly.

case class A(value: Int)

implicit def lift(single: A): A :: HNil = single :: HNil

def something[L <: HList](l: L)(implicit lUBConstraint: LUBConstraint[L, A],
                                isHCons: IsHCons[L]) = {
    println("works")
}

something(A(1) :: A(2) :: HNil) //works
something(A(1)) //not works
something(lift(A(1))) //works

something(A(1)) is not working. However, I use intellij idea and It can detect that lift is proper to use here.

Here is the error message from compiler.

inferred type arguments [Boot.A] do not conform to method something's type parameter bounds [L <: shapeless.HList] [error] something(A(1)) //not works [error] ^ [error]

type mismatch; [error] found : Boot.A [error] required: L [error] something(A(1))

could not find implicit value for parameter lUBConstraint: shapeless.LUBConstraint[L, Boot.A] [error] something(A(1)

1
In what way is it not working? Is there an error? If so, please provide the error as shown.Dekker1
I edited the question.Korkor

1 Answers

0
votes

IIRC Scala implicit conversions don't trigger to satisfy type bounds.

You can modify your definition of something to allow any such conversions to work:

def something[X, L <: HList](x: X)(
  implicit asHList: X => L,
           lUBConstraint: LUBConstraint[L, A],
           isHCons: IsHCons[L]
) = {
    println("works")
}

For single argument, this will use your lift function, and <:< from Predef for actual HLists