Abstract
We present a generic Haskell library for expressing rewrite rules with a safe treatment of variables and binders. Both sides of the rules are written as typed EDSL expressions, which leads to syntactically appealing rules and hides the underlying term representation. Matching is defined as an instance of Miller’s higher-order pattern unification and has the same complexity as first-order matching. The restrictions of pattern unification are captured in the types of the library, and we show by example that the library is capable of expressing useful simplifications that might be used in a compiler.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Similar content being viewed by others
Notes
- 1.
- 2.
- 3.
Note the partial type annotation in . It is used to constrain the type parameter of the RHS without saying anything about the representation of the RHS. Partial type signatures require the recent extension to GHC. However, this extension is not strictly needed: an equivalent formulation of the RHS would be .
- 4.
The property is almost true: it holds if we replace all wildcards in \(l\) with unique meta-variables.
- 5.
References
Antoy, S., Hanus, M.: Declarative programming with function patterns. In: Hill, P.M. (ed.) LOPSTR 2005. LNCS, vol. 3901, pp. 6–22. Springer, Heidelberg (2006)
Axelsson, E., Claessen, K.: Using circular programs for higher-order syntax: functional pearl. In: Proceedings of the 18th ACM SIGPLAN International Conference on Functional Programming, pp. 257–262. ACM, New York (2013)
Axelsson, E., Claessen, K., Dévai, G., Horváth, Z., Keijzer, K., Lyckegård, B., Persson, A., Sheeran, M., Svenningsson, J., Vajda, A.: Feldspar: a domain specific language for digital signal processing algorithms. In: 8th IEEE/ACM International Conference on Formal Methods and Models for Codesign, pp. 169–178. IEEE (2010)
Bahr, P., Hvitved, T.: Compositional data types. In: Proceedings of the Seventh ACM SIGPLAN Workshop on Generic Programming, pp. 83–94. ACM, New York (2011)
Brown, N.C., Sampson, A.T.: Matching and modifying with generics. In: Draft Proceedings of Trends in Functional Programming, pp. 304–318 (2008)
Carette, J., Kiselyov, O., Shan, C.C.: Finally tagless, partially evaluated: tagless staged interpreters for simpler typed languages. J. Funct. Programm. 19(5), 509–543 (2009)
Cervesato, I., Pfenning, F.: A linear spine calculus. J. Logic Comput. 13(5), 639–688 (2003)
Dévai, G.: Extended pattern matching for embedded languages. Annales Univ. Sci. Budapestiensis de Rolando Eötvös Nominatae, Sectio Comutatorica 36, 277–297 (2012)
Felgenhauer, B., Avanzini, M., Sternagel, C.: A Haskell library for term rewriting. CoRR abs/1307.2328 (2013). http://arxiv.org/abs/1307.2328
Goldfarb, W.D.: The undecidability of the second-order unification problem. Theoret. Comput. Sci. 13(2), 225–230 (1981)
Huet, G.: Résolution d’équations dans les langages d’ordre 1, 2,.., \(\omega \). Ph.D. thesis, Université Paris VII (1976)
Miller, D.: A logic programming language with lambda-abstraction, function variables, and simple unification. J. logic Comput. 1(4), 497–536 (1991)
Mohnen, M.: Context patterns in Haskell. In: Kluge, W. (ed.) IFL’96. LNCS, vol. 1268, pp. 41–57. Springer, Berlin, Heidelberg (1997)
Nadathur, G., Miller, D.: An overview of Lambda-Prolog. Technical report MS-CIS-88-40, University of Pennsylvania, Department of Computer and Information Science (1988)
van Noort, T., Yakushev, A.R., Holdermans, S., Jeuring, J., Heeren, B., Magalhães, J.P.: A lightweight approach to datatype-generic rewriting. J. Funct. Programm. 20, 375–413 (2010)
Norell, U.: Towards a practical programming language based on dependent type theory. Ph.D. thesis, Department of Computer Science and Engineering, Chalmers University of Technology, SE-412 96 Göteborg, Sweden, September 2007
Oosterhof, N., Hölzenspies, P., Kuper, J.: Application patterns. In: van Eekelen, M. (ed.) Trends in Functional Programming, pp. 370–382. Tartu University Press, Tallinn (2005)
Pfenning, F., Schürmann, C.: System description: twelf - a meta-logical framework for deductive systems. In: Ganzinger, H. (ed.) CADE 1999. LNCS (LNAI), vol. 1632, pp. 202–206. Springer, Heidelberg (1999)
Sculthorpe, N., Frisby, N., Gill, A.: The kansas university rewrite engine. J. Funct. Programm. 24, 434–473 (2014)
Serrano, A., Hage, J.: Feedback upon feedback. Presented at Trends in Functional Programming (2015). ftp://ftp-sop.inria.fr/indes/TFP15/TFP2015_submission_22.pdf
Swierstra, W.: Data types à la carte. J. Funct. Programm. 18, 423–436 (2008)
Wierzbicki, T.M.: Complexity of the higher order matching. In: Ganzinger, H. (ed.) CADE 1999. LNCS (LNAI), vol. 1632, pp. 82–96. Springer, Heidelberg (1999)
Yokoyama, T., Hu, Z., Takeichi, M.: Design and implementation of deterministic higher-order patterns (2005). http://takeichi.ipl-lab.org/yicho/YoHT05.pdf
Acknowledgements
This research was funded by the Swedish Foundation for Strategic Research (in the RAWFP project). The anonymous referees provided useful input.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2016 Springer International Publishing Switzerland
About this paper
Cite this paper
Axelsson, E., Vezzosi, A. (2016). Lightweight Higher-Order Rewriting in Haskell. In: Serrano, M., Hage, J. (eds) Trends in Functional Programming. TFP 2015. Lecture Notes in Computer Science(), vol 9547. Springer, Cham. https://doi.org/10.1007/978-3-319-39110-6_1
Download citation
DOI: https://doi.org/10.1007/978-3-319-39110-6_1
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-39109-0
Online ISBN: 978-3-319-39110-6
eBook Packages: Computer ScienceComputer Science (R0)