skip to main content
research-article

The HERMIT in the machine: a plugin for the interactive transformation of GHC core language programs

Published:13 September 2012Publication History
Skip Abstract Section

Abstract

The importance of reasoning about and refactoring programs is a central tenet of functional programming. Yet our compilers and development toolchains only provide rudimentary support for these tasks. This paper introduces a programmatic and compiler-centric interface that facilitates refactoring and equational reasoning. To develop our ideas, we have implemented HERMIT, a toolkit enabling informal but systematic transformation of Haskell programs from inside the Glasgow Haskell Compiler's optimization pipeline. With HERMIT, users can experiment with optimizations and equational reasoning, while the tedious heavy lifting of performing the actual transformations is done for them.

HERMIT provides a transformation API that can be used to build higher-level rewrite tools. One use-case is prototyping new optimizations as clients of this API before being committed to the GHC toolchain. We describe a HERMIT application - a read-eval-print shell for performing transformations using HERMIT. We also demonstrate using this shell to prototype an optimization on a specific example, and report our initial experiences and remaining challenges.

References

  1. F. L. Bauer, H. Ehler, A. Horsch, B. Moeller, H. Partsch, O. Paukner, and P. Pepper. The Munich Project CIP. Springer-Verlag, 1988. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Y. Bertot and P. Castéran. Interactive Theorem Proving and Program Development. Springer, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. R. Bird and O. de Moor. Algebra of Programming. Prentice Hall, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. P. Borovanský, C. Kirchner, H. Kirchner, and C. Ringeissen. Rewriting with strategies in ELAN: a functional semantics. International Journal of Foundations of Computer Science, 12 (1): 69--98, 2001.Google ScholarGoogle ScholarCross RefCross Ref
  5. M. Bravenboer, K. T. Kalleberg, R. Vermaas, and E. Visser. Stratego/XT 0.17. A language and toolset for program transformation. Science of Computer Programming, 72 (1-2): 52--70, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. C. M. Brown. Tool Support for Refactoring Haskell Programs. PhD thesis, University of Kent, 2008.Google ScholarGoogle Scholar
  7. A. Bundy, D. Basin, D. Hutter, and A. Ireland. Rippling: Meta-Level Guidance for Mathematical Reasoning. Cambridge University Press, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. R. M. Burstall and J. Darlington. A transformation system for developing recursive programs. Journal of the ACM, 24 (1): 44--67, 1977. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. D. Delahaye. A tactic language for the system Coq. In Logic for Programming and Automated Reasoning, pages 85--95. Springer, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. E. Dolstra. First class rules and generic traversals for program transformation languages. Technical report, Utrecht University, 2001.Google ScholarGoogle Scholar
  11. N. J. Foster, M. B. Greenwald, J. T. Moore, B. C. Pierce, and A. Schmitt. Combinators for bidirectional tree transformations: A linguistic approach to the view-update problem. Transactions on Programming Languages and Systems, 29 (3), 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. GHC Team. The Glorious Glasgow Haskell Compilation System User's Guide, Version 7.4.1, 2012. URL http://www.haskell.org/ghc.Google ScholarGoogle Scholar
  13. A. Gill. Introducing the Haskell equational reasoning assistant. In Haskell Workshop, pages 108--109. ACM, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. A. Gill. A Haskell hosted DSL for writing transformation systems. In Domain-Specific Languages, pages 285--309. Springer, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. A. Gill and G. Hutton. The worker/wrapper transformation. Journal of Functional Programming, 19 (2): 227--251, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. W. Guttmann, H. Partsch, W. Schulte, and T. Vullinghs. Tool support for the interactive derivation of formally correct functional programs. Journal of Universal Computer Science, 9 (2): 173--188, 2003.Google ScholarGoogle Scholar
  17. J. Harrison. Handbook of Practical Logic and Automated Reasoning. Cambridge University Press, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. R. Hinze. A new approach to generic functional programming. In Principles of Programming Languages, pages 119--132. ACM, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. R. Hughes. A novel representation of lists and its application to the function "reverse". Information Processing Letters, 22 (3): 141--144, 1986. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. O. Kiselyov, S. Peyton Jones, and C. Shan. Fun with type functions. In Reflections on the Work of C.A.R. Hoare, chapter 14, pages 301--331. Springer, 2010.Google ScholarGoogle Scholar
  21. R. Lämmel and S. Peyton Jones. Scrap your boilerplate: a practical design pattern for generic programming. In Types in Languages Design and Implementation, pages 26--37. ACM, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. R. Lämmel and S. Peyton Jones. Scrap more boilerplate: reflection, zips, and generalised casts. In International Conference on Functional Programming, pages 244--255. ACM, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. R. Lämmel and J. Visser. Typed combinators for generic traversal. In Practical Aspects of Declarative Programming, pages 137--154. Springer, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. R. Lämmel, S. Thompson, and M. Kaiser. Programming errors in traversal programs over structured data. Science of Computer Programming, 2013. To appear.Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. H. Li and S. Thompson. Tool support for refactoring functional programs. In Partial evaluation and semantics-based program manipulation, pages 199--203. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. A. Löh. Exploring Generic Haskell. PhD thesis, Utrecht University, 2004.Google ScholarGoogle Scholar
  27. J. P. Magalhães, A. Dijkstra, J. Jeuring, and A. Löh. A generic deriving mechanism for Haskell. In Haskell Symposium, pages 37--48. ACM, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. E. Meijer, M. M. Fokkinga, and R. Paterson. Functional programming with bananas, lenses, envelopes and barbed wire. In Functional Programming Languages and Computer Architecture, pages 124--144. Springer, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. B. O'Sullivan. http://hackage.haskell.org/package/criterion.Google ScholarGoogle Scholar
  30. S. Owre, J. M. Rushby, and N. Shankar. PVS: A prototype verification system. In International Conference on Automated Deduction, pages 748--752. Springer-Verlag, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. L. C. Paulson. The foundation of a generic theorem prover. Journal of Automated Reasoning, 5 (3): 363--397, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. S. Peyton Jones and A. L. M. Santos. A transformation-based optimiser for Haskell. Science of Computer Programming, 32 (1-3): 3--47, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. S. Peyton Jones, A. Tolmach, and T. Hoare. Playing by the rules: rewriting as a practical optimisation technique in GHC. In Haskell Workshop, pages 203--233. ACM, 2001.Google ScholarGoogle Scholar
  34. B. C. Pierce. Types and Programming Languages. MIT Press, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. A. Rodriguez, J. Jeuring, P. Jansson, A. Gerdes, O. Kiselyov, and B. C. d. S. Oliveira. Comparing libraries for generic programming in Haskell. In Haskell Symposium, pages 111--122. ACM, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. D. Sands. Higher-order expression procedures. In Partial evaluation and semantics-based program manipulation, pages 178--189. ACM, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. A. Santos. Compilation by Transformation in Non-Strict Functional Languages. PhD thesis, University of Glasgow, 1995.Google ScholarGoogle Scholar
  38. W. L. Scherlis. Expression procedures and program derivation. PhD thesis, Stanford University, 1980. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. T. Sheard and S. Peyton Jones. Template metaprogramming for Haskell. In Haskell Workshop, pages 1--16. ACM, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. M. Sulzmann, M. M. T. Chakravarty, S. Peyton Jones, and K. Donnelly. System F with type equality coercions. In Types in Language Design and Implementaion, pages 53--66. ACM, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. M. Tullsen. PATH, A Program Transformation System for Haskell. PhD thesis, Yale University, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. E. Visser. Program transformation with Stratego/XT: Rules, strategies, tools, and systems in StrategoXT-0.9. In Domain-Specific Program Generation, pages 216--238. Spinger, 2004.Google ScholarGoogle ScholarCross RefCross Ref
  43. E. Visser. A survey of strategies in rule-based program transformation systems. Journal of Symbolic Computation, 40 (1): 831--873, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. E. Visser, Z. Benaissa, and A. Tolmach. Building program optimizers with rewriting strategies. In International Conference on Functional Programming, pages 13--26. ACM, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. D. Vytiniotis, S. Peyton Jones, and J. P. Magalhães. Equality proofs and deferred type errors. In International Conference on Functional Programming. ACM, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. S. Weirich, D. Vytiniotis, S. Peyton Jones, and S. Zdancewic. Generative type abstraction and type-level computation. In Principles of Programming Languages, pages 227--240. ACM, 2011a. Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. S. Weirich, B. A. Yorgey, and T. Sheard. Binders unbound. In International Conference on Functional Programming, pages 333--345. ACM, 2011b. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. A. R. Yakushev, S. Holdermans, A. Löh, and J. Jeuring. Generic programming with fixed points for mutually recursive datatypes. In International Conference on Functional Programming, pages 233--244. ACM, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  49. B. A. Yorgey, S. Weirich, J. Cretin, S. Peyton Jones, D. Vytiniotis, and J. P. Magalhães. Giving Haskell a promotion. In Types in Language Design and Implementation, pages 53--66. ACM, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. The HERMIT in the machine: a plugin for the interactive transformation of GHC core language programs

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    • Published in

      cover image ACM SIGPLAN Notices
      ACM SIGPLAN Notices  Volume 47, Issue 12
      Haskell '12
      December 2012
      157 pages
      ISSN:0362-1340
      EISSN:1558-1160
      DOI:10.1145/2430532
      Issue’s Table of Contents
      • cover image ACM Conferences
        Haskell '12: Proceedings of the 2012 Haskell Symposium
        September 2012
        168 pages
        ISBN:9781450315746
        DOI:10.1145/2364506

      Copyright © 2012 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 13 September 2012

      Check for updates

      Qualifiers

      • research-article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!