[Haskell-cafe] Using GHC API to compile Haskell sources to CORE and CORE to binary
eir at cis.upenn.edu
Wed Jan 28 12:41:39 UTC 2015
I have plenty of experience with GHC Core, but none with the GHC API. I'll explain what I know.
GHC's Core language is alive and very well. It's described in many academic papers -- "Giving Haskell a Promotion" and "Safe Zero-Cost Coercions for Haskell" both contain nice descriptions of a theoretical version of the language. The actual language as implemented is described in https://github.com/ghc/ghc/blob/master/docs/core-spec/core-spec.pdf?raw=true though that is quite terse.
Expressions in Core are stored in the CoreExpr type, types are the Type type, and coercions are the Coercion type. The file coreSyn/CoreLint.hs performs typechecking over this language.
A desugared module is written in Core. If you know how to manipulate the GHC API into producing a desugared module (a ModGuts, I believe), you have a Core program. Alternatively, you can create your own ModGuts somehow, and then perhaps convince the GHC API to carry on with it.
Core is used for all of GHC's internal manipulations: simplifying & optimization. The fact that it's typechecked is a critical sanity check on GHC itself -- we want to know if a transformation changes any types! (They shouldn't.)
External Core, on the other hand, was a project that lived for some time, allowing a command-line interface for injecting Core into GHC, without even the GHC API. It had a printer and a parser. However, it bitrotted over the years and was recently removed, as the rot showed that no one was actually using it. However, if you are using the GHC API, I don't think that the lack of External Core should be an issue. I believe External Core's salient feature was its parser, and you don't need that as an API user.
I hope this is helpful!
On Jan 27, 2015, at 6:10 PM, Wojciech Danilo <wojciech.danilo at gmail.com> wrote:
> Hello All! :)
> Recently I've came across a problem and hopefully you could help me with it. Basically I and some people here are running a startup and we have created a language for processing images. This language has 2 interchangeable representations - textual and visual, dataflow one.
> Right now we are compiling it to haskell sources, but we want to move over GHC CORE. Getting into GHC has a high learning curve, as far as we see, and we would be very thankfull for any help with a minimal working example of compiling haskell sources to CORE and then CORE to binaries. I've posted couple days ago a detailed question on StackOverflow, here:
> I would be very thankful for any help or hints!
> All the best,
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe