Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strategy for desugaring Haskell

I'm developing a virtual machine for purely functional programs, and I would like to be able to test and use the the wide variety of Haskell modules already available. The VM takes as input essentially terms in the untyped lambda calculus. I'm wondering what would be a good way to extract such a representation from modern Haskell modules (eg. with MPTC's, pattern guards, etc.). I did a little research and there doesn't seem to be a tool that does this already (I would be delighted to be mistaken), and that's okay. I'm looking for an approach.

GHC Core seems too operationally focused, especially since one of the things the VM does is to change the evaluation order significantly. Are there any accessible intermediate representations that correspond more closely to the lambda calculus?

like image 577
luqui Avatar asked Dec 29 '10 02:12

luqui


3 Answers

The External Core for GHC is about as close to the lambda calculus as you're going to get, using GHC. Here is a link straight to the expression type if you want to jump right in.

  • Library for processing external core files
  • How to generate external core with GHC
  • An academic paper on its use
like image 116
Antoine Latter Avatar answered Nov 12 '22 21:11

Antoine Latter


EHC used to have this flow between representations:

HS -> EH -> Core -> Grin -> Silly

HS is obviously Haskell, EH is less sugary and used by the type checker, Core is the analogue to GHC's Core and Grin and Silly are lower level than that.

There is a paper describing EHC's architecture by Jeroen Fokker, where I've cribbed the above from, but it's probably out of date (I don't know that EHC still uses the Silly representation). I think that EHC provides parsers and pretty printers for each of its internal representations, which would be handy.

There's also York.Core from YHC which I've seen people speak more favorably of then GHC Core, but I don't know if there is a means of compiling "modern" Haskell into York.Core.

like image 42
stephen tetley Avatar answered Nov 12 '22 20:11

stephen tetley


Hm... Ever heard of the Haskell Kernel? I'm not sure what you need. It's some kind of desugared Haskell, and is essentially defined in the Haskell report. I'm not sure whether this is what you need.

like image 1
fuz Avatar answered Nov 12 '22 20:11

fuz