Skip to content

Instantly share code, notes, and snippets.

@ceedubs
Created March 5, 2015 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ceedubs/119f5fc72c4acd22e52a to your computer and use it in GitHub Desktop.
Save ceedubs/119f5fc72c4acd22e52a to your computer and use it in GitHub Desktop.
Weird implicit search failure with Shapeless At and Nat._0
package shapeless.examples
import shapeless._
import nat._
import ops.hlist._
object TableExample {
final case class Row[L <: HList](cells: L)
final case class Table[L <: HList](rows: L) {
def row[R <: HList](rowNumber: Nat)(implicit atR: At.Aux[L, rowNumber.N, Row[R]]): Row[R] =
atR(rows)
}
val test = Table(
Row(1 :: 2 :: 3 :: HNil) ::
Row(4 :: 5 :: 6 :: HNil) ::
Row(7 :: 8 :: 9 :: HNil) ::
HNil)
test.row(1) // Row(4 :: 5 :: 6 :: HNil)
test.row(2) // Row(7 :: 8 :: 9 :: HNil)
// all of these below fail to compile with errors like:
// could not find implicit value for parameter atR: shapeless.ops.hlist.At.Aux[shapeless.::[shapeless.examples.TableExample.Row[shapeless.::[Int,shapeless.::[Int,shapeless.::[Int,shapeless.HNil]]]],shapeless.::[shapeless.examples.TableExample.Row[shapeless.::[Int,shapeless.::[Int,shapeless.::[Int,shapeless.HNil]]]],shapeless.::[shapeless.examples.TableExample.Row[shapeless.::[Int,shapeless.::[Int,shapeless.::[Int,shapeless.HNil]]]],shapeless.HNil]]],nat_$macro$3.N,shapeless.examples.TableExample.Row[R]]
//test.row(0)
//test.row(Nat(0))
//test.row(Nat._0)
}
@ceedubs
Copy link
Author

ceedubs commented Mar 5, 2015

It looks like it works if I change row to:

    def row(rowNumber: Nat)(implicit atR: At[L, rowNumber.N]): atR.Out =
      atR(rows)

But this doesn't work when I need to go through a chain of ops with At being the first one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment