Even .head doesn’t work.
What changes do I need to make to make this work?
import shapeless._
import HList._
import Nat._
scala> case class Foo[A](a: A)
defined class Foo
scala> case class Bar[A](f: Foo[A])
defined class Bar
scala> val xs = Foo(23) :: Foo("blah") :: HNil
xs: shapeless.::[Foo[Int],shapeless.::[Foo[java.lang.String],shapeless.HNil]] = Foo(23) :: Foo(blah) :: HNil
scala> object mapper extends (Foo ~> Bar) {
| def apply[A](f: Foo[A]) = Bar(f)
| }
defined module mapper
scala> xs map mapper
res13: mapper.Out = Bar(Foo(23)) :: Bar(Foo(blah)) :: HNil
scala> res13.apply[_1]
<console>:38: error: could not find implicit value for parameter at: shapeless.At[mapper.Out,shapeless.Nat._1]
res13.apply[_1]
^
scala> res13.head
<console>:38: error: could not find implicit value for parameter c: shapeless.IsHCons[mapper.Out]
res13.head
^
Works for me exactly as written, at least with the latest 2.10.0-SNAPSHOT,
Notice that the type inferred for
res0above isBar[Int] :: Bar[String] :: HNilrather thanmapper.Out… I suspect that this is a difference in behaviour between 2.9.x and 2.10.0-SNAPSHOT.If you’re stuck with 2.9.x then I think you should be able to work around the problem by ascribing
Bar[Int] :: Bar[String] :: HNilto yourres13explicitly … obviously that’s more verbose, but c’est la vie.