[GHC] #11078: Access to module renaming with reifyModule, in TemplateHaskell

GHC ghc-devs at haskell.org
Wed Nov 11 08:30:40 UTC 2015


#11078: Access to module renaming with reifyModule, in TemplateHaskell
-------------------------------------+-------------------------------------
        Reporter:  cipher1024        |                Owner:
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Template Haskell  |              Version:  7.10.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Description changed by jstolarek:

Old description:

> 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.

New description:

 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`.

 {{{#!hs
 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

 {{{#!hs
 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.

--

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11078#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list