International Conference on Interactive Theorem Proving

ITP 2015: Interactive Theorem Proving pp 453-468 | Cite as

Pattern Matches in HOL:

A New Representation and Improved Code Generation
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 9236)

Abstract

Pattern matching is ubiquitous in functional programming and also very useful for definitions in higher-order logic. However, it is not directly supported by higher-order logic. Therefore, the parsers of theorem provers like HOL4 and Isabelle/HOL contain a pattern-compilation algorithm. Internally, decision trees based on case constants are used. For non-trivial case expressions, there is a big discrepancy between the user’s view and the internal representation.

This paper presents a new general-purpose representation for case expressions that mirrors the input syntax in the internal representation closely. Because of this close connection, the new representation is more intuitive and often much more compact. Complicated parsers and pretty printers are no longer required. Proofs can more closely follow the user’s intentions, and code generators can produce better code. Moreover, the new representation is more general than the currently used representation, supporting guards, patterns with multiple occurrences of the same bound variable, unbound variables, arithmetic expressions in patterns, and more. This work has been implemented in the HOL4 theorem prover and integrated into CakeML’s proof-producing code generator.

Notes

Acknowledgements

The second author was partially supported by the Royal Society UK and the Swedish Research Council.

References

  1. 1.
    Augustsson, L.: Compiling pattern matching. In: FPCA, pp. 368–381 (1985). http://dx.doi.org/10.1007/3-540-15975-4_48
  2. 2.
    Harrison, J.: HOL light: an overview. In: Berghofer, S., Nipkow, T., Urban, C., Wenzel, M. (eds.) TPHOLs 2009. LNCS, vol. 5674, pp. 60–66. Springer, Heidelberg (2009). http://dx.doi.org/10.1007/978-3-642-03359-9_4 CrossRefGoogle Scholar
  3. 3.
    Krauss, A.: Partial recursive functions in higher-order logic. In: Furbach, U., Shankar, N. (eds.) IJCAR 2006. LNCS (LNAI), vol. 4130, pp. 589–603. Springer, Heidelberg (2006) CrossRefGoogle Scholar
  4. 4.
    Kumar, R., Arthan, R., Myreen, M.O., Owens, S.: HOL with definitions: semantics, soundness, and a verified implementation. In: Klein, G., Gamboa, R. (eds.) ITP 2014. LNCS, vol. 8558, pp. 308–324. Springer, Heidelberg (2014). http://dx.doi.org/10.1007/978-3-319-08970-6_20 Google Scholar
  5. 5.
    Kumar, R., Myreen, M.O., Norrish, M., Owens, S.: CakeML: a verified implementation of ML. In: Jagannathan, S., Sewell, P. (eds.) POPL, pp. 179–192. ACM (2014)Google Scholar
  6. 6.
    Maranget, L.: Compiling pattern matching to good decision trees, September 2008Google Scholar
  7. 7.
    Myreen, M.O., Owens, S.: Proof-producing translation of higher-order logic into pure and stateful ML. J. Funct. Program. 24(2–3), 284–315 (2014)MATHMathSciNetCrossRefGoogle Scholar
  8. 8.
    Okasaki, C.: Purely Functional Data Structures. Cambridge University Press, Cambridge (1998) CrossRefGoogle Scholar
  9. 9.
    Peyton Jones, S.L.: The Implementation of Functional Programming Languages (Prentice-Hall International Series in Computer Science). Prentice-Hall Inc., Upper Saddle River (1987) Google Scholar
  10. 10.
    Slind, K.: Function definition in higher-order logic. In: von Wright, J., Harrison, J., Grundy, J. (eds.) TPHOLs 1996. LNCS, vol. 1125, pp. 381–397. Springer, Heidelberg (1996) CrossRefGoogle Scholar
  11. 11.
    Slind, K., Norrish, M.: A brief overview of HOL4. In: Mohamed, O.A., Muñoz, C., Tahar, S. (eds.) TPHOLs 2008. LNCS, vol. 5170, pp. 28–32. Springer, Heidelberg (2008) CrossRefGoogle Scholar
  12. 12.
    Wadler, P.: Views: A way for pattern matching to cohabit with data abstraction. In: POPL, pp. 307–313. ACM (1987)Google Scholar
  13. 13.
    Wenzel, M., Paulson, L.C., Nipkow, T.: The isabelle framework. In: Mohamed, O.A., Muñoz, C., Tahar, S. (eds.) TPHOLs 2008. LNCS, vol. 5170, pp. 33–38. Springer, Heidelberg (2008). http://dx.doi.org/10.1007/978-3-540-71067-7_7 CrossRefGoogle Scholar

Copyright information

© Springer International Publishing Switzerland 2015

Authors and Affiliations

  • Thomas Tuerk
    • 1
  • Magnus O. Myreen
    • 2
    • 3
  • Ramana Kumar
    • 3
  1. 1.Independent ScholarBrechenGermany
  2. 2.CSE DepartmentChalmers University of TechnologyGothenburgSweden
  3. 3.Computer LaboratoryUniversity of CambridgeCambridgeUK

Personalised recommendations