The HERMIT in the Tree
This paper describes our experience using the HERMIT toolkit to apply well-known transformations to the internal core language of the Glasgow Haskell Compiler. HERMIT provides several mechanisms to support writing general-purpose transformations: a domain-specific language for strategic programming specialized to GHC’s core language, a library of primitive rewrites, and a shell-style–based scripting language for interactive and batch usage.
There are many program transformation techniques that have been described in the literature but have not been mechanized and made available inside GHC — either because they are too specialized to include in a general-purpose compiler, or because the developers’ interest is in theory rather than implementation. The mechanization process can often reveal pragmatic obstacles that are glossed over in pen-and-paper proofs; understanding and removing these obstacles is our concern. Using HERMIT, we implement eleven examples of three program transformations, report on our experience, and describe improvements made in the process.
KeywordsGHC Mechanization Transformation Worker/wrapper
We thank Ed Komp for his work on implementing the HERMIT system, Jason Reich for suggesting the Mean example, and the anonymous reviewers for their constructive comments and feedback. This material is based upon work supported by the National Science Foundation under Grant No. 1117569.
- 5.GHC Team: The Glorious Glasgow Haskell Compilation System User’s Guide, Version 7.6.2. http://www.haskell.org/ghc (2013)
- 8.Guttmann, W., Partsch, H., Schulte, W., Vullinghs, T.: Tool support for the interactive derivation of formally correct functional programs. J. Univ. Comput. Sci. 9(2), 173–188 (2003)Google Scholar
- 12.Li, H., Thompson, S.: A domain-specific language for scripting refactoring in Erlang. In: de Lara, J., Zisman, A. (eds.) FASE 2012. LNCS, vol. 7212, pp. 501–515. Springer, Heidelberg (2012)Google Scholar
- 20.Peyton Jones, S., Tolmach, A., Hoare, T.: Playing by the rules: rewriting as a practical optimisation technique in GHC. In: 2001 ACM SIGPLAN Haskell Workshop, pp. 203–233. ACM, New York (2001)Google Scholar
- 21.Pierce, B.C.: Types and Programming Languages. MIT Press, Cambridge (2002)Google Scholar
- 22.Santos, A.: Compilation by transformation in non-strict functional languages. Ph.D. thesis, University of Glasgow (1995)Google Scholar
- 23.Schmidt, D.A.: Denotational Semantics: A Methodology for Language Development. Allyn and Bacon, Newton (1986)Google Scholar
- 24.Sculthorpe, N., Frisby, N., Gill, A.: KURE: A Haskell-embedded strategic programming language with custom closed universes (in preparation)Google Scholar
- 25.Sculthorpe, N., Hutton, G.: Work it, wrap it, fix it, fold it (in preparation)Google Scholar
- 26.Sulzmann, M., Chakravarty, M.M.T., Peyton Jones, S., Donnelly, K.: System F with type equality coercions. In: 3rd ACM SIGPLAN Workshop on Types in Language Design and Implementaion, pp. 53–66. ACM, New York (2007)Google Scholar
- 27.Tullsen, M.: PATH, a program transformation system for Haskell. Ph.D. thesis, Yale University (2002)Google Scholar
- 28.Wadler, P.: The concatenate vanishes. University of Glasgow, Tech. rep. (1989)Google Scholar