Question about Haskell AST
j2ren at ucsd.edu
Mon Jan 24 18:20:21 CET 2011
That is exactly what I needed. However, although I was able to get the patterns from the parse tree for test modules that I wrote, I was not able to get the parsetrees for the Haskell base library modules.
For example, I am trying to use Data/List.hs as a test. Here's the code
defaultErrorHandler defaultDynFlags $ do
runGhc (Just libdir) $ do
dflags <- getSessionDynFlags
target <- guessTarget targetFile Nothing
modSum <- getModSummary $ mkModuleName "Data.List"
When I try this, I get
"AstWalker: panic! (the 'impossible' happened)
(GHC version 7.0.1 for x86_64-apple-darwin):
lexical error at character 'i'
It appears this error comes from "load LoadAllTargets"
Any ideas how I can get parse trees for the Haskell base modules?
Sure, I can augment that wiki page.
From: Simon Peyton-Jones [simonpj at microsoft.com]
Sent: Tuesday, January 11, 2011 12:06 AM
To: Jane Ren; glasgow-haskell-users at haskell.org
Subject: RE: Question about Haskell AST
desugarModule returns a GHC.DesugaredModule
Inside a DesugaredModule is a field dm_core_module :: HscTypes.ModGuts
Inside a ModGuts is a field mg_binds :: [CoreSyn.CoreBind]
And there are your bindings! Does that tell you what you wanted to know?
PS: When you have it clear, would you like to augment the Wiki http://haskell.org/haskellwiki/GHC/As_a_library to describe what you learned? That way others can benefit.
| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-haskell-
| users-bounces at haskell.org] On Behalf Of Jane Ren
| Sent: 10 January 2011 17:21
| To: glasgow-haskell-users at haskell.org
| Subject: Question about Haskell AST
| I need to be able to take a piece of Haskell source code and get an
| simplified, typed, intermediate representation of the AST, which means I need
| to use compiler/coreSyn/CoreSyn.lhs
| So I'm first trying to get the desguaredModule of the source code with
| modSum <- getModSummary $ mkModuleName "..."
| p <- parseModule modSum
| t <- typecheckModule p
| d <- desugarModule t
| Now I'm really stuck on figuring out how to connect the variable d of type
| desugaredModule to compiler/coreSyn/CoreSyn.lhs to get Expr patterns like
| App, Let, Case, etc.
| Also, is it correct to get the deguaredModule first? At least CoreSyn.lhs
| seems to suggest this.
| Any suggestions would be greatly apprecia
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
More information about the Glasgow-haskell-users