<div dir="ltr">At a guess, because the ghc package defaults to being hidden (it's creating a new ghc instance at runtime, so the visibility of the ghc package when compiling your code is not relevant) you need to do the ghc-api equivalent of "-package ghc". Or for testing just "ghc-pkg expose ghc".</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Aug 2, 2019 at 3:47 PM Sam Halliday <<a href="mailto:sam.halliday@gmail.com">sam.halliday@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">To answer my own question with a solution and another question:<br>
<br>
Sam Halliday writes:<br>
> I'm mostly interested in gathering information about symbols and their<br>
> type signatures. As a first exercise: given a module+import section<br>
> for a haskell source file, I want to find out which symbols (and their<br>
> types) are available. Like :browse in ghci, but programmatically.<br>
<br>
This is answered by Stephen Diehl's blog post on the ghc api! How lucky<br>
I am: <a href="http://www.stephendiehl.com/posts/ghc_01.html" rel="noreferrer" target="_blank">http://www.stephendiehl.com/posts/ghc_01.html</a><br>
<br>
He points to getNamesInScope<br>
<br>
Unfortunately I'm getting zero Names back when loading a file that<br>
imports several modules from ghc. Is there something I'm missing in the<br>
following?<br>
<br>
module Main where<br>
<br>
import Control.Monad<br>
import Control.Monad.IO.Class<br>
import GHC<br>
import GHC.Paths (libdir)<br>
<br>
main = runGhc (Just libdir) $ do<br>
dflags <- getSessionDynFlags<br>
void $ setSessionDynFlags $ dflags {<br>
hscTarget = HscInterpreted<br>
, ghcLink = LinkInMemory<br>
}<br>
addTarget $ Target (TargetFile "exe/Main.hs" Nothing) False Nothing<br>
res <- load LoadAllTargets<br>
liftIO $ putStrLn $ showPpr dflags res<br>
names <- getNamesInScope<br>
liftIO $ putStrLn $ "seen " <> (show $ length names) <> " Names"<br>
<br>
<br>
-- <br>
Best regards,<br>
Sam<br>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div>brandon s allbery kf8nh</div><div><a href="mailto:allbery.b@gmail.com" target="_blank">allbery.b@gmail.com</a></div></div></div></div></div>