Map on HList in method with Poly1 based on type parameter of class

functional-programming, hlist, scala, shapeless, type-level-computation

Solution

This is a bug in the Scala compiler (both 2.9.2 and 2.10.0-RC1).

As a workaround, if you split the creation of the instance of `Test` and the invocation of the `test` method across two expression then it works as expected,

scala> val t = new Test(1 :: HNil, 'a)
t: Test[shapeless.::[Int,shapeless.HNil],Symbol] = Test@4b153b34

scala> t.test
res0: shapeless.::[(Symbol, Int),shapeless.HNil] = ('a,1) :: HNil

Problem

I have class, parameterized with `HList` and some other type. How can I use `map` on `HList` in one of its methods? Compilation of this code throws `java.lang.AssertionError`: ``` class Test[L <: HList, P](l: L, p: P) { type Cont[T] = (P, T) object generator extends (Id ~> Cont) { def apply[T](t: T) = p -> t } def test(implicit m: Mapper[generator.type, L]) = { l map generator } } new Test(1 :: HNil, 'a).test // java.lang.AssertionError ``` My goal is this kind of result: ``` type Cont[T] = (Symbol, T) val p = 'a object generator extends (Id ~> Cont) { def apply[T](t: T) = p -> t } scala> (1 :: 'b' :: HNil) map generator res0: shapeless.::[(Symbol, Int),shapeless.::[(Symbol, Char),shapeless.HNil]] = ('a,1) :: ('a,b) :: HNil ```

Original source