T8639_api.hs 965 Bytes
Newer Older
Simon Peyton Jones's avatar
Simon Peyton Jones committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
module Main where

import GHC
import GhcMonad
import Outputable
import System.IO
import System.Environment( getArgs )

main
 = do { [libdir] <- getArgs
      ; runGhc (Just libdir) $ do
           flags <- getSessionDynFlags
           setSessionDynFlags (flags{ hscTarget = HscInterpreted, ghcLink = LinkInMemory})
           target <- guessTarget "T8639_api_a.hs" Nothing
           setTargets [target]
           load LoadAllTargets
17
           imps <- mapM parseImportDecl ["import Prelude", "import System.IO", "import T8639_api_a"]
Simon Peyton Jones's avatar
Simon Peyton Jones committed
18 19 20 21
           setContext (map IIDecl imps)

           -- With the next line, you get an "Not in scope" exception.
           -- If you comment out this runStmt, it runs without error and prints the  type.
22 23
           execStmt "putStrLn (show 3)" execOptions
           execStmt "hFlush stdout" execOptions
Simon Peyton Jones's avatar
Simon Peyton Jones committed
24

25
           ty <- exprType TM_Inst "T8639_api_a.it"
Simon Peyton Jones's avatar
Simon Peyton Jones committed
26 27
           liftIO (putStrLn (showPpr flags ty))
       ; hFlush stdout }