2

If I run:

> runQ [p| zs@(z:_) |]
AsP zs_46 (InfixP (VarP z_47) GHC.Types.: WildP)

I'd like to replace zs and z with names I generate myself. I can replace z:

> let z = mkName "z"
> runQ [p| zs@($(varP z):_) |]
AsP zs_48 (InfixP (VarP z) GHC.Types.: WildP)

but I cannot figure out how to replace zs. Is there a way to do it inside quotes or do I have to resort to asP, etc ... ?

rityzmon
  • 1,945
  • 16
  • 26

1 Answers1

2

You probably can't. Splices only work for patterns, expressions, declarations, and types. This isn't any of those because it's just a name.

Similarly you can't splice names in other places with Template Haskell

[d| $(mkName "f") x = x |] -- invalid

Using asP as you mentioned the closest you get is

asP (mkName "zs") [p| z:_ |]

glguy
  • 1,090
  • 7
  • 8