Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Found some interesting GHC API calls
- Loading branch information
1 parent
3282092
commit 84519a3
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module A where | ||
|
||
f :: Int -> Int -> Int | ||
f x y = x + y | ||
|
||
data SomeData = NotReally | JustOne Int | JustTwo Int Double |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,6 @@ executable quickver | |
|
||
build-depends: | ||
base == 4.* | ||
, ghc == 7.2.* | ||
, ghc-paths == 0.1.* | ||
, QuickCheck == 2.4.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,39 @@ | ||
module Main (main) where | ||
|
||
import qualified DynFlags as G | ||
import Data.Maybe (catMaybes) | ||
import qualified DataCon as G | ||
import qualified GHC as G | ||
import GHC.Paths (libdir) | ||
import qualified Outputable as G | ||
import qualified TyCon as G | ||
import qualified Var as G | ||
|
||
main :: IO () | ||
main = putStrLn "Quick Version 0.1" | ||
main = do | ||
res <- example | ||
mapM_ (putStrLn . G.showSDoc . G.ppr) res | ||
|
||
example :: IO [G.Type] | ||
example = | ||
G.defaultErrorHandler G.defaultLogAction $ do | ||
G.runGhc (Just libdir) $ do | ||
dflags <- G.getSessionDynFlags | ||
G.setSessionDynFlags dflags | ||
target <- G.guessTarget "examples/A.hs" Nothing | ||
G.setTargets [target] | ||
G.load G.LoadAllTargets | ||
|
||
m <- G.findModule (G.mkModuleName "A") Nothing | ||
(Just info) <- G.getModuleInfo m | ||
|
||
exports <- mapM (G.lookupName) (G.modInfoExports info) | ||
|
||
return $ map extractType $ catMaybes exports | ||
|
||
extractType :: G.TyThing -> G.Type | ||
extractType (G.AnId var) = G.varType var | ||
extractType (G.ATyCon tycon) = G.tyConKind tycon | ||
extractType (G.ADataCon dcon) = G.dataConRepType dcon | ||
extractType (G.ACoAxiom _) = error "extractType: ACoAxiom" | ||
extractType (G.AClass _) = error "extractType: AClass" |