-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.hs
42 lines (35 loc) · 1.38 KB
/
main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import Control.Monad
import Control.Monad.IO.Class
import Outputable
import OccName
import GHC
import GHC.Paths (libdir)
-- | Just toying around with the GHC api for now.
main :: IO ()
main = do
runGhc (Just libdir) $ do
-- Initialize dynflags
df <- getSessionDynFlags
setSessionDynFlags df
-- find all loadable modules
mds <- packageDbModules False
forM_ mds $ \mod -> do
mmi <- getModuleInfo mod -- :: m (Maybe ModuleInfo). Why is it a maybe?
case mmi of
Nothing -> return () -- Dunno what this means...
Just mi -> do
let exportedThings = modInfoExports mi
forM_ exportedThings $ \r -> do
let str = showSDoc df $ pprOccName $ getOccName r
mthing <- modInfoLookupName mi r
let msig = case mthing of
Just (AnId thing) -> Just $ showSDocOneLine df $ pprParendType $ idType thing
_ -> Nothing
case msig of
Just sig -> liftIO $ do
putStr str
putStr " --> "
putStr sig
putStr "; "
putStrLn $ moduleNameString $ moduleName mod
_ -> return () -- Not a value