Hacle

A Translator from Haskell to Clean


Contents

Introduction

In my final year at the University of York I undertook a student project entitled Haskell to Clean Translation. The aim was to develop a translator which is capable of reading in any given Haskell'98 program and writing out a semantically equivalent Clean one. Why? To investigate the suitability of the Clean compiler for compiling Haskell programs, i.e.

Can the Clean compiler, in combination with this tool, produce faster executables than existing Haskell compilers?

The purpose of this web page is to document our findings in the area of Haskell to Clean Translation, and to make publicly available a tool for performing the translation.

Our Current Findings

Our tool Hacle can translate programs which conform to a slightly restricted Haskell'98 standard. These limitations are described in detail on our limitations page. A very important part of our work is a large piece of documentation named Issues in Haskell to Clean Translation. It defines the translations that are necessary to get from a Haskell program to a semantically equivalent Clean program.

We evaluate Hacle according to two criteria:

  1. By comparing the efficiency of the executables produced by the hybrid Hacle then Clean compilation system against those produced by the GHC compiler.
  2. By measuring the completeness of the Hacle translator.

A large table of results (including our test conditions) is available on our evaluation page. Here though, we simply bring forward a few results that are sufficient to form some basic yet important conclusions.

GHC Versus Clean: The following results will help us to gauge whether or not the Hacle then Clean compilation system can produce faster executables than GHC:

ProgramInstanceEx. Time (GHC) Ex. Time (Clean)Notes
countdown[1..7], 1000038.33s 57.8shSetBuffering
digits-of-e220005.41s 1.23sovl,getArgs
mateshinkman2.88s 1.51sgetArgs
last-piecedefault8.3s 15.82sgetArgs

These results show two cases where the Hacle then Clean compilation system produces faster executables than the GHC compiler. Likewise they also show two cases where the opposite is true. So, since the Hacle then Clean compilation system is potentially beneficial, its completeness is now of importance.

Hacle's Completeness: The following result will help us gauge the completeness of the translator:

ProgramInstanceEx. Time (GHC) Ex. Time (Clean)Notes
Haclemate1.81s 2.67sovl,getArgs,rat

This result shows that Hacle is capable of translating itself. Hacle is written in approximately fifteen and half thousand lines of Haskell code (actually this figure includes comments but not standard libraries, which probably balance each other out!). A very large proportion of features provided by Haskell'98 have been used in writing Hacle. This result, therefore, seems quite positive.

On the negative side however, observe the three notes which are mentioned in the result. A note represents a modification that was required to the input program to make it conform to the subset of Haskell'98 that Hacle actually supports (see the evaluation page for what these notes actually mean). However, I can tell you that these three manual modifications required only a few minutes to perform.

My Dissertation

For more details you can read my project dissertation (although it's slightly out of date compared to these web pages).

The ``Hacle'' Tool

The Hacle tool has been made available for download. The package includes a README file that describes how the system may be installed. A small FAQ may also prove helpful.

Future Work

It is perhaps quite unlikely that the tool will be widely adopted by typical Haskell programmers, so future improvements to it are perhaps not that worthwhile.

However, questions remain on why GHC and Clean outperform each other on various programs. Currently though, I do not have the knowledge to speculate on this.

Finally, the Hacle project has been informative for me, and the results, however predictable, are interesting.

Acknowledgements

The project was originally defined in the York under-graduate project database by Dr. Olaf Chitil. Olaf subsequently moved to the University of Kent before the project really got started. As a result I was left in the capable hands of Dr. Malcolm Wallace, who gave me very useful feedback on my writings and helped verify some of my proposed translations. Though I should say that if any mistakes are found, they are of course completely my own fault. It is safe to say that this project wouldn't have progressed to this stage without the constant encouragement of both Olaf and Malcolm.

You may be wondering did I actually write fifteen and a half thousand lines of code all by myself? Thankfully not! The following work made developing this tool possible in the limited time period available:

  • Happy by Simon Marlow and Andy Gill
  • HsParser by Simon Marlow and Sven Panne
  • The Pretty Module by John Hughes and Simon Peyton Jones
  • Haskell Pretty Printer by Noel Winstanley
  • A Formal Specification for the Haskell 98 Module System by Iavor Diatchki, Mark Jones and Thomas Hallgren
  • DrIFT by Noel Winstanley, Malcolm Wallace, Joost Visser and John Meacham

Related Work

In related works, Hajnalka Hegedus wrote a nice document entitled Transforming Haskell Structures to Clean. Also, Peter Divianszky developed quite a complete Haskell Frontend for Clean.