Navigation Menu

Skip to content
ilyasergey edited this page Dec 29, 2012 · 31 revisions

This is the Github project page for a version of GHC extended with a form of syntactic sugar for applicative functors in the ApplicativeFix type class. This type class has an observable effectful recursion primitive afix. The alet construct allows writing applicative terms with observable effectful recursion with a low syntactic overhead. All of this is the topic of a PEPM 2013 paper titled "Fixing Idioms - Choosing fixpoints in applicative DSLs".

Trying out ApplicativeFix

To try out our modified version of GHC, we recommend you to follow these steps:

Getting the sources

You will need to get both the augmented compiler and the standard libraries, based on the GHC branch ghc-7.4.

  1. git clone git@github.com:ilyasergey/GHC-XAppFix.git
  2. cd GHC-XAppFix
  3. ./sync-all --testsuite -r http://darcs.haskell.org get -o ghc-7.4
  4. ./sync-all --testsuite -r http://darcs.haskell.org checkout -t ghc-7.4/ghc-7.4
  5. cd libraries/base
  6. git remote add github git@github.com:ilyasergey/GHC-XAppFix-BaseLibrary.git
  7. git fetch github appfix:appfix
  8. git checkout appfix
  9. cd ../..

Getting tests

To fetch the augmented testsuite:

  1. cd testsuite
  2. git remote add github git@github.com:ilyasergey/GHC-XAppFix-TestSuite.git
  3. git fetch github appfix:appfix
  4. git checkout appfix
  5. cd ..

Building

To build the compiler, follow the standard instructions from Haskell Wiki, duplicated here for quick reference:

  1. perl boot
  2. ./configure
  3. make

Known limitations:

  • top-level alets are not supported
  • type signatures for alet-bound variables are not supported

Examples:

Prerequisites:

We have prepared some known working examples. To try them out, you need to install some libraries from Hackage first. We recommend the following:

  1. cabal update
  2. cabal install --with-compiler=$PWD/inplace/bin/ghc-stage2 --with-hc-pkg=$PWD/inplace/bin/ghc-pkg uu-parsinglib
  3. cabal install --with-compiler=$PWD/inplace/bin/ghc-stage2 --with-hc-pkg=$PWD/inplace/bin/ghc-pkg memoize

The examples

We have prepared a tarball containing known working examples, including those discussed in the paper. Starting points are the files Parser.hs, FRP.hs and Memoize.hs. The examples employ functions from other modules which are also included. If you save the tarball in /tmp, you can use it as follows.

  1. GHCDIR=<the directory where you built GHC>
  2. cd /tmp
  3. tar xzf demo.tar.gz
  4. cd demo
  5. $GHCDIR/inplace/bin/ghc-stage2 --interactive Parser.hs

The last command can be similarly used on the other files in the demo dir. Note that our current prototype compiler still generates a lot of debug output, which we recommend you to ignore...

Interesting parts of the implementation

Arity-generic primitive nafix

If you want to look at the implementation of the arity-generic nafix function, which we do not discuss in our ICFP submission, it is defined in the file libraries/base/Control/Applicative/GeneriFix.hs if you correctly followed the installation steps outlined below. You can also find the file online.

Compiler changes

Our compiler changes are isolated in the parser, renamer, type-checker and desugarer. If you want to get a view of our changes, you are probably best to do a git diff of our branch against the GHC-7.4 branch.