Re: [Haskell-cafe] Generating Haskell Code out of Haskell AST (GHC API)

I accidentally didn't send that email to haskell-cafe, so I'm pasting it
here also:
Alan - I do NOT want to generate Haskell code. I want only to generate AST
and compile it.
The question about generating the code was only to have a "debugging tool"
- to see if the generated AST is good - I wanted to generate the Haskell
code only to check if its correct, but normally I would not do it, because
it makes no sense to generate AST -> code -> AST (by GHC) again etc :)
Additional - I want to connect to GHC's type-checking also and translate
the errors to be appropriate to my language syntax - so maybe the pure GHC
API is the best way to go?
2013/7/19 John Blackbox
Additional - I want to connect to GHC's type-checking also and translate the errors to be appropriate to my language syntax.
2013/7/19 John Blackbox
Alan - I do NOT want to generate Haskell code. I want only to generate AST and compile it. The question about generating the code was only to have a "debugging tool" - to see if the generated AST is good - I wanted to generate the Haskell code only to check if its correct, but normally I would not do it, because it makes no sense to generate AST -> code -> AST (by GHC) again etc :)
2013/7/19 AlanKim Zimmerman
I have not used haskell-src-exts so I may be talking out of turn, but it seems that if you want to generate an AST which you then turn into source code and compile it makes more sense than using than GHC AST, which has a number of wrinkles, including fields that are only valid at certain phases of the compilation process.
For my purposes, in the Haskell Refactorer, I need access to the renaming and type-checking, which to my knowledge is not currently available in haskell-src-exts, although there is work happening to bring it in, e.g. https://github.com/haskell-suite/haskell-names.
On Fri, Jul 19, 2013 at 10:09 AM, John Blackbox < blackbox.dev.ml@gmail.com> wrote:
Thank you! So, if I'm writing a compiler of custom language, which I want to generate Haskell AST and further compile it with GHC, you prefer something like haskell-src-exts over pure GHC API?
2013/7/19 Antoine Latter
The package haskell-src-exts is a lot less intimidating if all you are trying to do is programmatically generate Haskell source:
http://hackage.haskell.org/package/haskell-src-exts
The base types are here:
http://hackage.haskell.org/packages/archive/haskell-src-exts/1.13.5/doc/html...
This module has some helper function for generating parts of the AST:
http://hackage.haskell.org/packages/archive/haskell-src-exts/1.13.5/doc/html...
Hi! I dont know GHC API very well, but I want to generate AST of a
On Thu, Jul 18, 2013 at 1:11 PM, John Blackbox
wrote: program using GHC API. Is there any standard method to generate Haskell code out of it? (something like "print_this_for_me_please" function? :D
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi John,
Alan - I do NOT want to generate Haskell code. I want only to generate AST and compile it. The question about generating the code was only to have a "debugging tool" - to see if the generated AST is good - I wanted to generate the Haskell code only to check if its correct, but normally I would not do it, because it makes no sense to generate AST -> code -> AST (by GHC) again etc :) Additional - I want to connect to GHC's type-checking also and translate the errors to be appropriate to my language syntax - so maybe the pure GHC API is the best way to go?
I don't know what kind of language you're writing, but I don't think that this is the easiest approach. Just trying to convert a GHC error in something meaningful for your language sounds like a quite painful undertaking, which will end in some big heuristic algorithm. I think, that getting good and meaningful errors for your language you will need to do it by yourself. The result will be easier to maintain and extend. I don't quite understand why you're thinking that GHC is at all the right tool. Well, I don't know exactly what you're really trying to do, but have you already looked at LLVM (http://llvm.org/)? Greetings, Daniel

Hi, Am Freitag, den 19.07.2013, 11:19 +0200 schrieb John Blackbox:
The question about generating the code was only to have a "debugging tool" - to see if the generated AST is good - I wanted to generate the Haskell code only to check if its correct, but normally I would not do it, because it makes no sense to generate AST -> code -> AST (by GHC) again etc :)
it does make sense: ASCII (or today, Unicode text) is a much easier and more stable interface than some ADT of a library. There is a good reason why GHC generates llvm files and calls clang on them, instead of generating the LLVM AST with some libllvm. Same for all the pre-processors (happy, alex) – they all go through the serialized form. It will be easier to plug components together, to inspect the intermediate Haskell code or even modify it. Of course if you need features not available via the command line, using the API might be required. But for your own sake I suggest you avoid it if possible. Greetings, Joachim -- Joachim “nomeata” Breitner mail@joachim-breitner.de • http://www.joachim-breitner.de/ Jabber: nomeata@joachim-breitner.de • GPG-Key: 0x4743206C Debian Developer: nomeata@debian.org
participants (3)
-
Daniel Trstenjak
-
Joachim Breitner
-
John Blackbox