1

私は shapeless 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 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]

def 入力の戻り値の型を削除しても、エラーは発生しません。

4

1 に答える 1

1

私が投稿した要点がうまく機能することが判明しました-それはIntellijの問題でした

gist.github.com/kumaramit01/80ca29b46d2c07e55b0b

戻り値の型を次のように定義した場合、Intellij は構文エラーを示し続けました。

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

アミット

于 2015-03-14T00:58:02.417 に答える