FW: GHC as a library
Simon Peyton-Jones
simonpj at microsoft.com
Wed May 30 12:12:43 EDT 2007
Good questions.
Fwding to GHC users, to get myself out of the inner loop
Simon
-----Original Message-----
From: Kenny Zhuo Ming Lu [mailto:luzm at comp.nus.edu.sg]
Sent: 30 May 2007 12:44
To: Simon Peyton-Jones
Subject: GHC as a library
Dear Simon,
I would like to bother you with some questions regarding GHC-as-a-library.
I am currently planning to use/call GHC to infer/typecheck a given
haskell module my project.
I've been following the examples (in particular, the interactive evaluator)
in http://haskell.org/haskellwiki/GHC/As_a_library
In the following program I managed to parse and type check the given
Haskell module, (Test.hs)
using the call GHC.checkModule function.
\begin{code}
main = do
session <- GHC.newSession GHC.JustTypecheck (Just "Test.hs")
dflags1 <- GHC.getSessionDynFlags session
(dflags2, packageIds) <- Packages.initPackages dflags1
GHC.setSessionDynFlags session dflags2{GHC.hscTarget=GHC.HscNothing}
let name = "Test.hs"
target <- GHC.guessTarget name Nothing
GHC.addTarget session target
GHC.load session GHC.LoadAllTargets
let preludeModule = GHC.mkModule (PackageConfig.stringToPackageId
"base") (GHC.mkModuleName "Prelude")
GHC.setContext session [] [preludeModule]
m_checkedModule <- GHC.checkModule session (GHC.mkModuleName "Test")
...
\end{code}
I am hoping to retrieve the inferred types of the declared Ids in Test.hs
At this stage, what I obtain is a value of type Maybe CheckedModule.
Then I looked into the definition of CheckedModule,
\begin{code}
data CheckedModule =
CheckedModule { parsedSource :: ParsedSource,
renamedSource :: Maybe RenamedSource,
typecheckedSource :: Maybe TypecheckedSource,
checkedModuleInfo :: Maybe ModuleInfo
}
\end{code}
I attempted to look inside two of them,
\begin{code}
typecheckedSource :: Maybe TypecheckedSource,
checkedModuleInfo :: Maybe ModuleInfo
\end{code}
In typecheckedSource, I can only access the function definitions with
type annotations, but not the data type declaration.
In checkedModuleInfo, I can only access the "Names" of the exported
entities, and but not their (inferred) types are not present.
So my question is, "Where I can access the inferred types?"
Could you please advice?
Thanks you very much.
Best Regards,
Kenny
More information about the Glasgow-haskell-users
mailing list