GHC API: modInfoIsExportedName, String -> Name?

Hi, I wanted to use the GHC API to find if a symbol is exported from a module. The function 'modInfoIsExportedName :: ModuleInfo -> Name -> Bool' seems to do what I want, but how do I convert a symbol string into a 'Name'? Thanks for any hints! Greetings, Daniel

Hi. Correct me if I am wrong, but you are not supposed to construct 'Name's yourself. The point is that they are unique and hiding the constructors is a step towards preserving the invariants. Here's how I would do something like 'map nameOccName . modInfoExports' and then search for an OccName (which you can construct using mkOccName). Unfortunately I don't have GHC handy so I can't test this Cheers - Dan
On 19 Oct 2013, at 17:58, Daniel Trstenjak
wrote: Hi,
I wanted to use the GHC API to find if a symbol is exported from a module.
The function 'modInfoIsExportedName :: ModuleInfo -> Name -> Bool' seems to do what I want, but how do I convert a symbol string into a 'Name'?
Thanks for any hints!
Greetings, Daniel _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Hi Dan,
Correct me if I am wrong, but you are not supposed to construct 'Name's yourself. The point is that they are unique and hiding the constructors is a step towards preserving the invariants.
Ok, I almost expected something like this.
Here's how I would do something like 'map nameOccName . modInfoExports' and then search for an OccName (which you can construct using mkOccName).
I already tried it this way, but if you're doing this for a lot of modules, than quite a lot of time is just spend creating the list for the returned symbols, which is in my case than immediately discarded after the search. Greetings, Daniel

This is something we've had to do in LiquidHaskell. You might look at the function `stringLookupEnv`: https://github.com/ucsd-progsys/liquidhaskell/blob/master/Language/Haskell/L... the key bits are: *hscParseIdentifier*http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/HscMain.html#v:hsc... :: HscEnv -> String -> IO (Located RdrName)http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/HscMain.html#v:hsc... *tcRnLookupRdrName*http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/TcRnDriver.html#v:... :: HscEnv -> RdrName -> IO (Messages, Maybe [Name])http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/TcRnDriver.html#v:... Note that both of these require that you have an `HscEnv` in hand. Also, the hoogle query: "String -> m Name +ghc" brought up: parseNamehttp://www.haskell.org/ghc/docs/latest/html/libraries/ghc/InteractiveEval.ht... :: GhcMonad m => String -> m [Name]http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/InteractiveEval.ht... which seems like it may be helpful if you don't want to manually pass around HscEnvs... Hope this helps! On Sat, Oct 19, 2013 at 10:19 AM, Daniel Trstenjak < daniel.trstenjak@gmail.com> wrote:
Hi Dan,
Correct me if I am wrong, but you are not supposed to construct 'Name's yourself. The point is that they are unique and hiding the constructors is a step towards preserving the invariants.
Ok, I almost expected something like this.
Here's how I would do something like 'map nameOccName . modInfoExports' and then search for an OccName (which you can construct using mkOccName).
I already tried it this way, but if you're doing this for a lot of modules, than quite a lot of time is just spend creating the list for the returned symbols, which is in my case than immediately discarded after the search.
Greetings, Daniel
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Hi Ranjit, unfortunately both versions don't seem to work.
parseName :: GhcMonad m => String -> m [Name]
This version yields an exception - I can't remember the exact text - but something like symbol not found.
hscParseIdentifier :: HscEnv -> String -> IO (Located RdrName) tcRnLookupRdrName :: HscEnv -> RdrName -> IO (Messages, Maybe [Name])
By this version the returned names by tcRnLookupRdrName are empty and also the returned messages are empty, or 'printBagOfErrors' doesn't output anything for them. Greetings, Daniel
participants (3)
-
Dan Frumib
-
Daniel Trstenjak
-
Ranjit Jhala