1

I've got a class that depends on an HList, has a polymorphic function and a method to map this function over the list. The strange thing is that this method can only be invoked on a val, otherwise the compilation fails:

import shapeless._
import shapeless.ops.hlist.Mapper

class C[L <: HList](l: L) {
    object f extends Poly1 {
        implicit def whatever[T] = at[T]{_ => ()}
    }
    def g(implicit m: Mapper[f.type,L]) = ()
}
val c = new C(1 :: "s" :: HNil)

// this line compiles:
val v1 = c.g

// compilation fails if c is inlined:
val v2 = (new C(1 :: "s" :: HNil)).g
// error: could not find implicit value for parameter m:
//   Mapper[_1.f.type, Int :: String :: HNil]]]

Is there a way to overcome such behaviour while keeping f inside C? I've tried to extract the method g to another class or object, but it didn't help.

ps_ttf
  • 1,096
  • 7
  • 15
  • possible duplicate of [Map on HList in method with Poly1 based on type parameter of class](http://stackoverflow.com/questions/13098296/map-on-hlist-in-method-with-poly1-based-on-type-parameter-of-class) – senia Feb 26 '14 at 11:45
  • seems like this question discusses a different error – ps_ttf Feb 27 '14 at 08:29

0 Answers0