Works for me exactly the same as it is written, at least with the latest 2.10.0-SNAPSHOT,
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[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
res0: shapeless.::[Bar[Int],shapeless.::[Bar[String],shapeless.HNil]] = Bar(Foo(23)) :: Bar(Foo(blah)) :: HNil
scala> res0[_1]
res1: Bar[String] = Bar(Foo(blah))
scala> res0.head
res2: Bar[Int] = Bar(Foo(23))
Please note that the type specified for res0above is Bar[Int] :: Bar[String] :: HNilnot mapper.Out... I suspect that this is a difference in behavior between 2.9.x and 2.10.0-SNAPSHOT.
If you are stuck with 2.9.x, then I think you should solve this problem by explicitly attaching Bar[Int] :: Bar[String] :: HNilto your res13... obviously this is more verbose, but c'est la vie.
source
share