Skip to content

Instantly share code, notes, and snippets.

@chrisdone
Created June 26, 2018 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdone/6fcb9f1cba6324148d481fcd4eab6af6 to your computer and use it in GitHub Desktop.
Save chrisdone/6fcb9f1cba6324148d481fcd4eab6af6 to your computer and use it in GitHub Desktop.
ghc api demo
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE CPP #-}
import GHC
import GHC.Paths
import DynFlags
import Language.Haskell.TH.LanguageExtensions
targetFile :: [Char]
targetFile = "B.hs"
main :: IO ()
main = do
defaultErrorHandler defaultFatalMessager defaultFlushOut $ do
runGhc (Just libdir) $ do
dflags <- getSessionDynFlags
let dflags' = foldl xopt_set dflags [ImplicitPrelude]
_ <- setSessionDynFlags dflags'
target <- guessTarget targetFile Nothing
setTargets [target]
_ <- load LoadAllTargets
modSum <- getModSummary $ mkModuleName "B"
p <- parseModule modSum
t <- typecheckModule p
pure ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment