Access to module renaming with reifyModule, in TemplateHaskell
I am writing a bit of TemplateHaskell for stringing together QuickCheck style specifications. I require every module containing properties to export a symbol called axiom_set
. Then, my checkAxioms
function finds all the axiom_set
symbols from modules imported where I call checkAxioms
.
checkAxioms :: DecsQ
checkAxioms = do
ModuleInfo ms <- reifyModule =<< thisModule
forM_ ms $ \mi@(Module _ m) -> do
runIO . print =<< lookupValueName (modString m ++ ".axiom_set")
The above code should find all the imported axiom_set
symbols. However, if Module.Axioms
defines axiom_set
but that I imported as follows
import Module.Axioms as MA
my code can't find MA.axiom_set
.
I think either modString
should return MA
in the case of Module.Axioms
or there should be a function that takes a symbol and a module and constructs a Name
referring to the symbol in the module and considering possible renamings of modules.