Roman
Roman

Reputation: 5699

Shapeless zipWithKeys: Could not find implicit parameter

I've been playing around with shapeless recently. There is this very basic thing I can't wrap my head around:

import shapeless._
import syntax.singleton._
import record._

object NotWorking {
  val result = ("value" :: HNil).zipWithKeys("key" :: HNil)
} 

I expect this snippet to output an extensible Record. But the compiler is not able to find an implicit for withKeys:

could not find implicit value for parameter withKeys: shapeless.ops.hlist.ZipWithKeys[shapeless.::[String,shapeless.HNil],shapeless.::[String,shapeless.HNil]]
[error]     ("value" :: HNil).zipWithKeys("key" :: HNil)

It's even more confusing, as the example I took form Shapeless' test cases works perfectly:

import shapeless._
import syntax.singleton._
import record._

object ShamelesslyStolenFromTests {
  val orig =
    ("intField" ->> 1) ::
    ("boolField" ->> true) ::
    HNil

  val result = orig.values.zipWithKeys(orig.keys)
}

What am I missing?

Upvotes: 1

Views: 217

Answers (1)

Dmytro Mitin
Dmytro Mitin

Reputation: 51658

The following code compiles:

  import shapeless._
  import syntax.singleton._
  import record._

  object FinallyWorking {
    val result = ("value" :: HNil).zipWithKeys[Witness.`"key"`.T :: HNil]("key".narrow :: HNil)
  }

So it seems this was an issue with type inference for type parameter of the method.

Upvotes: 3

Related Questions