1
votes

I am using shapeless 2.1.0 -scala 2.11, jdk 1.7: I have a trait

trait Input[T]{
  def location:String
}

 object location extends Poly1 {
      implicit def caseInput[T] = at[Input[T]](l => l.location)
 }

val list = new Input[String] {def location:String="/tmp"} :: HNil

list.map(location)

This returns correctly in my console

shapeless2.::[String,shapeless2.HNil] = /tmp :: HNil

However when I have the exact same logic in a function -where the HList is returned to me from another function call and I map function on it I get a compile time error

:could not find implicit value for parameter mapper: shapeless.ops.hlist.Mapper[location.type,shapeless.::[Input[String]{...},shapeless.HNil]]

I suspect I am probably missing some implicits. I have checked the shapeless tests and documentation -hopefully I didn't miss anything too obvious.

I can create a complete example to recreate the issue if it's not something obvious -thanks for reading.

Best, Amit

Updated: With an example

trait Input[T]{ def location:String def value:T }

 trait location extends Poly1 {
    implicit def caseList[T] = at[Input[T]](l => l.location)
  }


  object testfun extends location {
    implicit val atString = at[Input[String]](_.location)
    implicit val atInt = at[Input[Int]](_.location)
    implicit val atLong = at[Input[Long]](_.location)
  }

  def inputs:HList={
    val str = new Input[String]{
      override def location: String = "/tmp/string"
      override def value: String = "here it is"
    }
    val ints = new Input[Int]{
      override def location: String = "/tmp/1"
      override def value: Int = 1
    }
    val longs = new Input[Long]{
      override def location: String = "/tmp/1l"
      override def value: Long = 1l
    }
    str::ints::longs::HNil
  }
  >>>println(inputs.map(testfun))

 could not find implicit value for parameter mapper: shapeless.ops.hlist.Mapper[HListTest.testfun.type,shapeless.HList]

If I were to remove the return type of the def inputs, I don't get any errors.

1
It's really not going to be possible to help without being able to see the calling context in the failing case.Miles Sabin
Yes. Sorry Miles -attached an exampleAmit
You've defined the result type of inputs as HList which throws away the type information needed by the Mapper. Try defining it as Input[String] :: Input[Int] :: Input[Long] :: HNil or allow it to be inferred.Miles Sabin
How can I have it inferred? The example that I have above is simplified -in my real code, the abstract class is typed and provides the input return type similar toAmit
Timed out editing the comment: gist.github.com/kumaramit01/80ca29b46d2c07e55b0bAmit

1 Answers

1
votes

It turned out that the gist that I have posted works fine -it was an issue with Intellij

gist.github.com/kumaramit01/80ca29b46d2c07e55b0b

Intellij kept on indicating syntax error when I had return type defined as

Input[String] :: Input[Int] :: Input[Long] :: HNil

Amit