I do not think (I guess) that there is a way to associate a name in a signature of type Template Haskell (for GHC ≤ 7.10). To still use quasi-cycling, you can try to process the AST after that to indicate the name where it is needed (and leave it unchanged):
setName :: Name -> DecsQ -> DecsQ setName = fmap . map . sn where sn n (SigD _ t) = SigD nt sn n (ValD (VarP _) xy) = ValD (VarP n) xy sn _ d = d mkFunction n = setName (mkName n) [d| n :: Integer -> Integer n = \x -> x + 2 |]
This has been tested on GHC 7.10 and is likely to work with past and future versions of GHC with minor modifications.
To what extent is it less or more verbose than directly spelling AST. This will depend on the frequency that you record as ads and the complexity of the cited code.
The above setName function setName obviously be violated if you use it in an ad with multiple functions (or recursive functions). To handle this, you could write a reName function in the same vein.
source share