1

I want to write a compiler from another language to produce terms in Haskell Core, and call GHC on the result. Are there any methods to do this? The compiler is not written in Haskell, so it would have to communicate via a serialization format or FFI. I have read about .hcr files for getting core from GHC, but I don't know how to read it back in to finish compilation. Alternatively, I could try to write a plain Haskell file, but this would require a lot of explicit type applications and quoted identifiers, and it seems error prone.

Related: Using GHC API to compile Haskell sources to CORE and CORE to binary discusses the .hcr format and a GHC API that might help, but AFAICT the OP's question wasn't actually answered. Would a GHC plugin help here?

Mario Carneiro
  • 1,548
  • 1
  • 18
  • 32
  • Counter-interpretation: the question you linked to *was* answered (namely: can't be done with existing tools, so you gotta build it yourself), you just don't like the answer. – Daniel Wagner Feb 15 '19 at 15:28
  • @DanielWagner I'm actually okay with the "build it yourself" answer, but no one is answering the question "*How* can I build it myself?" As in, what needs to be done, is it a GHC plugin or extension, something using the API, or what? – Mario Carneiro Feb 16 '19 at 22:01
  • The question @AlexisKing suggested has good pointers on that. My executive summary is "compile to Haskell itself and toss unsafeCoerce in everywhere" or "use the GHC API to build up a Core term directly without serializing to disk first". – Daniel Wagner Feb 17 '19 at 01:15

0 Answers0