GHC API: modInfoIsExportedName, String -> Name?

Ranjit Jhala jhala at cs.ucsd.edu
Sat Oct 19 18:32:51 UTC 2013


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/Liquid/Bare.hs#L731

the key bits are:

*hscParseIdentifier*<http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/HscMain.html#v:hscParseIdentifier>
::
HscEnv -> String -> IO (Located
RdrName)<http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/HscMain.html#v:hscParseIdentifier>

*tcRnLookupRdrName*<http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/TcRnDriver.html#v:tcRnLookupRdrName>
::
HscEnv -> RdrName -> IO (Messages, Maybe
[Name])<http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/TcRnDriver.html#v:tcRnLookupRdrName>

Note that both of these require that you have an `HscEnv` in hand.

Also, the hoogle query: "String -> m Name +ghc" brought up:

parseName<http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/InteractiveEval.html#v:parseName>
::
GhcMonad m => String -> m
[Name]<http://www.haskell.org/ghc/docs/latest/html/libraries/ghc/InteractiveEval.html#v:parseName>

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 at 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20131019/55e22652/attachment.html>


More information about the Glasgow-haskell-users mailing list