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 :: HscEnv -> String -> IO (Located RdrName)

tcRnLookupRdrName :: HscEnv -> RdrName -> IO (Messages, Maybe [Name])

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

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

parseName :: GhcMonad m => String -> m [Name]

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