I'm writing a template haskell splice, and am struggling to generate the right kind of Name
s. If I want to generate a known name (say, a function f
), I can use 'f
. This requires f
to be in scope where I'm defining the splice, not where it's used, which is exactly what I want.
Now I want the same thing, but for a dynamic name. For example, say my splice takes an n :: Int
as an argument. I want to generate "f" ++ show n
as a Name
, looked up at the splice definition site, not the use site.
I've tried a couple of options: mkName
and lookupValueName
both require the name to be in scope at the use site. The single quote syntax needs a literal name, not a dynamic one.
Finally I started experimenting with mkNameG
. Since the functions come from the same package as I'm using them in, I started with the package name, but that gave errors Can't find interface-file declaration for variable the-package-name:Some.Module.f0
. After some source reading I found places where the package name "main"
was used. That seems to work in GHCi, but when compiling I still get the same error.
Is there any way to do this? I could enumerate all the options of course, but I'd like to avoid that, since the whole point of this exercise is to make the code more dynamic.