[Haskell-cafe] ghc-api Static Semantics?
nominolo at googlemail.com
Thu Jan 26 14:31:34 CET 2012
On 26 January 2012 09:24, Christopher Brown <cmb21 at st-andrews.ac.uk> wrote:
> Hi Thomas,
> By static semantics I mean use and bind locations for every name in the
Right, that's what the renamer does in GHC. The GHC AST is parameterised
over the type of identifiers used. The three different identifier types
- RdrName: is the name as it occurred in source code. This is the output
of the parser.
- Name: is basically RdrName + unique ID, so you can distinguish two
"x"s bound at different locations (this is what you want). This is the
output of the renamer.
- Id: is Name + Type information and consequently is the output of the
String --parser--> HsModule RdrName --renamer--> HsModule Name
--type-checker--> HsBinds Id
Since you can't hook in-between renamer and type checker, it's perhaps more
accurately depicted as:
String --parser--> HsModule RdrName --renamer+type-checker-->
(HsModule Name, HsBinds Id)
The main reasons why it's tricky to use the GHC API are:
1. You need to setup the environment of packages etc. E.g., the renamer
needs to look up imported modules to correctly resolve imported names (or
give a error).
2. The second is that the current API is not designed for external use.
As I mentioned, you cannot run renamer and typechecker independently,
there are dozens of invariants, there are environments being updated by the
various phases, etc. For example, if you want to generate code it's
probably best to either generate HsModure RdrName or perhaps the Template
Haskell API (never tried that path).
> I'm steering towards haskell-src-exts right now as the sheer complexity
of the ghc-api is putting me off. I need something simple, as I can't be
spending all my time learning the ghc-api and hacking it together to do
what I want. It does look a bit of a mess. Just trying to do simple things
like parsing a file and showing its output proved to be much more
complicated than it really needed to be
> We have decided to take it on. :)
Could you clarify that? Are you doing everything in haskell-src-exts or
are you using the GHC API and translate the result into haskell-src-exts?
The former might be easier to implement, the latter could later be extended
to give you type info as well (without the need to implement a whole type
checker that most likely will bit rot compared to GHC sooner or later).
Push the envelope. Watch it bend.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe