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.
This is a preview of subscription content, access via your institution.
For clarity of presentation we assume the function is in uncurried form, but CV is valid for functions that take any number of arguments; see .
Curly braces denote scoping: within a scope it is impossible to navigate above the node at which the scope starts, and when the scope ends the cursor returns to the starting node.
There is also a case-split command, which does not inline \( x \) in the alternatives.
Bird, R.S.: Tabulation techniques for recursive programs. ACM Comput.Surv. 12(4), 403–417 (1980)
Burstall, R.M., Darlington, J.: A transformation system for developing recursive programs. J. ACM 24(1), 44–67 (1977)
Chin, W.N., Khoo, S.C., Jones, N.: Redundant call elimination via tupling. Fundam. Informaticae 69(1–2), 1–37 (2006)
Farmer, A., Gill, A., Komp, E., Sculthorpe, N.: The HERMIT in the machine: a plugin for the interactive transformation of GHC core language programs. In: 2012 ACM SIGPLAN Haskell Symposium, pp. 1–12. ACM, New York (2012)
GHC Team: The Glorious Glasgow Haskell Compilation System User’s Guide, Version 7.6.2. http://www.haskell.org/ghc (2013)
Gill, A.: Introducing the Haskell equational reasoning assistant. In: 2006 ACM SIGPLAN Haskell Workshop, pp. 108–109. ACM, New York (2006)
Gill, A., Hutton, G.: The worker/wrapper transformation. J. Funct. Program. 19(2), 227–251 (2009)
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)
Hu, Z., Iwasaki, H., Takeichi, M., Takano, A.: Tupling calculation eliminates multiple data traversals. In: 2nd ACM SIGPLAN International Conference on Functional Programming, pp. 164–175. ACM, New York (1997)
Hughes, R.J.M.: A novel representation of lists and its application to the function “reverse”. Inf. Process. Lett. 22(3), 141–144 (1986)
Hutton, G.: Programming in Haskell. Cambridge University Press, Cambridge (2007)
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)
Li, H., Thompson, S., Orosz, G., Tóth, M.: Refactoring with wrangler, updated: data and process refactorings, and integration with eclipse. In: 7th ACM SIGPLAN Erlang Workshop, pp. 61–72. ACM, New York (2008)
Li, H., Thompson, S., Reinke, C.: The Haskell refactorer, HaRe, and its API. Electron. Notes Theor. Comput. Sci. 141(4), 29–34 (2005)
Liu, Y.A., Stoller, S.D.: Dynamic programming via static incrementalization. Higher-Order Symbolic Comput. 16(1–2), 37–62 (2003)
Pettorossi, A.: A powerful strategy for deriving efficient programs by transformation. In: 1984 ACM Symposium on LISP and Functional Programming, pp. 273–281. ACM, New York (1984)
Peyton Jones, S.: The Implementation of Functional Programming Languages. Prentice Hall, New York (1987)
Peyton Jones, S.L., Launchbury, J.: Unboxed values as first class citizens in a non-strict functional language. In: 5th ACM Conference on Functional Programming Languages and Computer Architecture, pp. 636–666. Springer, Heidelberg (1991)
Jones Peyton, S., Santos, A.L.M.: A transformation-based optimiser or Haskell. Sci. Comput. Program. 32(1–3), 3–47 (1998)
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)
Pierce, B.C.: Types and Programming Languages. MIT Press, Cambridge (2002)
Santos, A.: Compilation by transformation in non-strict functional languages. Ph.D. thesis, University of Glasgow (1995)
Schmidt, D.A.: Denotational Semantics: A Methodology for Language Development. Allyn and Bacon, Newton (1986)
Sculthorpe, N., Frisby, N., Gill, A.: KURE: A Haskell-embedded strategic programming language with custom closed universes (in preparation)
Sculthorpe, N., Hutton, G.: Work it, wrap it, fix it, fold it (in preparation)
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)
Tullsen, M.: PATH, a program transformation system for Haskell. Ph.D. thesis, Yale University (2002)
Wadler, P.: The concatenate vanishes. University of Glasgow, Tech. rep. (1989)
Yorgey, B.A., Weirich, S., Cretin, J., Peyton Jones, S., Vytiniotis, D., Magalhães, J.P.: Giving Haskell a promotion. In: 7th ACM SIGPLAN Workshop on Types in Language Design and Implementation, pp. 53–66. ACM, New York (2012)
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.
Editors and Affiliations
Rights and permissions
© 2013 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Sculthorpe, N., Farmer, A., Gill, A. (2013). The HERMIT in the Tree. In: Hinze, R. (eds) Implementation and Application of Functional Languages. IFL 2012. Lecture Notes in Computer Science(), vol 8241. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-41582-1_6
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-41581-4
Online ISBN: 978-3-642-41582-1
eBook Packages: Computer ScienceComputer Science (R0)