Reputation: 675
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. Any advice?
Upvotes: 4
Views: 96
Reputation: 7078
I don't think there's a way to do that. This seems to be a limitation of TemplateHaskell.
It kinda makes sense to have only fully qualified names in ModuleInfo
s list of imported modules, but the fact that we can't use those fully qualified names in lookupValueName
is bad. I think we need a variant of lookupValueName
or lookupName
that takes a Module
as argument.
I suggest openning an issue at GHC issue tracker: https://ghc.haskell.org/trac/ghc/newticket We have ongoing work to improve TH in the next major release. Part of the work is about improving the package documentation, exported functions etc. This can be one of the improvements.
Upvotes: 3