Skip to main content

The HERMIT in the Tree

Mechanizing Program Transformations in the GHC Core Language

Part of the Lecture Notes in Computer Science book series (LNTCS,volume 8241)

Abstract

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.

Keywords

  • GHC
  • Mechanization
  • Transformation
  • Worker/wrapper

This is a preview of subscription content, access via your institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • DOI: 10.1007/978-3-642-41582-1_6
  • Chapter length: 18 pages
  • Instant PDF download
  • Readable on all devices
  • Own it forever
  • Exclusive offer for individuals only
  • Tax calculation will be finalised during checkout
eBook
USD   54.99
Price excludes VAT (USA)
  • ISBN: 978-3-642-41582-1
  • Instant PDF download
  • Readable on all devices
  • Own it forever
  • Exclusive offer for individuals only
  • Tax calculation will be finalised during checkout
Softcover Book
USD   72.00
Price excludes VAT (USA)
Fig. 1.
Fig. 2.

Notes

  1. 1.

    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 [28].

  2. 2.

    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.

  3. 3.

    There is also a case-split command, which does not inline \( x \) in the alternatives.

References

  1. Bird, R.S.: Tabulation techniques for recursive programs. ACM Comput.Surv. 12(4), 403–417 (1980)

    CrossRef  MathSciNet  MATH  Google Scholar 

  2. Burstall, R.M., Darlington, J.: A transformation system for developing recursive programs. J. ACM 24(1), 44–67 (1977)

    CrossRef  MathSciNet  MATH  Google Scholar 

  3. Chin, W.N., Khoo, S.C., Jones, N.: Redundant call elimination via tupling. Fundam. Informaticae 69(1–2), 1–37 (2006)

    MathSciNet  MATH  Google Scholar 

  4. 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)

    CrossRef  Google Scholar 

  5. GHC Team: The Glorious Glasgow Haskell Compilation System User’s Guide, Version 7.6.2. http://www.haskell.org/ghc (2013)

  6. Gill, A.: Introducing the Haskell equational reasoning assistant. In: 2006 ACM SIGPLAN Haskell Workshop, pp. 108–109. ACM, New York (2006)

    CrossRef  Google Scholar 

  7. Gill, A., Hutton, G.: The worker/wrapper transformation. J. Funct. Program. 19(2), 227–251 (2009)

    CrossRef  MATH  Google Scholar 

  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 

  9. 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)

    CrossRef  Google Scholar 

  10. Hughes, R.J.M.: A novel representation of lists and its application to the function “reverse”. Inf. Process. Lett. 22(3), 141–144 (1986)

    CrossRef  Google Scholar 

  11. Hutton, G.: Programming in Haskell. Cambridge University Press, Cambridge (2007)

    CrossRef  MATH  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 

  13. 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)

    CrossRef  Google Scholar 

  14. Li, H., Thompson, S., Reinke, C.: The Haskell refactorer, HaRe, and its API. Electron. Notes Theor. Comput. Sci. 141(4), 29–34 (2005)

    CrossRef  Google Scholar 

  15. Liu, Y.A., Stoller, S.D.: Dynamic programming via static incrementalization. Higher-Order Symbolic Comput. 16(1–2), 37–62 (2003)

    CrossRef  MATH  Google Scholar 

  16. 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)

    CrossRef  Google Scholar 

  17. Peyton Jones, S.: The Implementation of Functional Programming Languages. Prentice Hall, New York (1987)

    MATH  Google Scholar 

  18. 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)

    CrossRef  Google Scholar 

  19. Jones Peyton, S., Santos, A.L.M.: A transformation-based optimiser or Haskell. Sci. Comput. Program. 32(1–3), 3–47 (1998)

    CrossRef  MATH  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 

  29. 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)

    CrossRef  Google Scholar 

Download references

Acknowledgements

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.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Neil Sculthorpe .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and Permissions

Copyright information

© 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

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-41582-1_6

  • Published:

  • 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)