首页 文章

HList Poly1 Mapper未找到参数映射器的隐式值

提问于
浏览
1

我使用无形2.1.0 -scala 2.11,jdk 1.7:我有一个特点

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)

这在我的控制台中正确返回

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

但是,当我在一个函数中有完全相同的逻辑 - 其中HList从另一个函数调用返回给我并且我在其上映射函数时出现编译时错误

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

我怀疑我可能错过了一些暗示 . 我已经检查过无形测试和文档 - 但是我并没有错过任何太明显的东西 .

我可以创建一个完整的示例来重新创建问题,如果它不是明显的东西 - 谢谢阅读 .

最好,阿米特

更新:举个例子

trait输入[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]

如果我要删除def输入的返回类型,我不会收到任何错误 .

1 回答

  • 1

    事实证明,我发布的要点很好 - 这是Intellij的一个问题

    gist.github.com/kumaramit01/80ca29b46d2c07e55b0b

    当我将返回类型定义为时,Intellij继续指示语法错误

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

    阿米特

相关问题