2

Essentially, I want something like this:

class FoldFn(l: HList) extends Poly {
  // stuff
}

def doStuff[L <: HList](l: L)(implicit folder: LeftFolder.Aux[L, Int, FoldFn, Int]): Int =
  l.foldLeft(0)(new FoldFn(l))(folder)

It fails to compile with:

type mismatch
found   : shapeless.ops.hlist.LeftFolder.Aux[L,Int,FoldFn,Int]
 (which expands to)  shapeless.ops.hlist.LeftFolder[L,Int,FoldFn]{type Out = Int}  
required: shapeless.ops.hlist.LeftFolder[L,Int,op.type]

new FoldFn(l) obviously has the type FoldFn, but the compiler won't accept the LeftFolder instance.
How can I get this to work?

HMPerson1
  • 29
  • 1
  • 4
  • 1
    You need a stable identifier for the polymorphic function value, which makes this tricky. One solution is to use a combination of `mapConst` and `zip`—see [this thread](https://groups.google.com/d/msg/shapeless-dev/P5DXRgnzqkY/Z5UA9sUX0I4J) for some discussion. – Travis Brown Jan 03 '15 at 03:40
  • I recently faced a similar issue, this might help you: http://stackoverflow.com/questions/25288806/dynamically-parametrize-poly1-function-in-shapeless/25316124#25316124 – Gabriele Petronella Jan 03 '15 at 12:19

0 Answers0