Deterministic Higher-Order Patterns for Program Transformation

  • Tetsuo Yokoyama
  • Zhenjiang Hu
  • Masato Takeichi
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 3018)


Higher-order patterns, together with higher-order matching, enable concise specification of program transformation, and have been implemented in several program transformation systems. However,higher-order matching in general is nondeterministic, and the matching algorithm is so expensive that even second-order matching is NP-complete. It is orthodox to impose constraint on the form of patterns to obtain the desirable matches satisfying certain properties such as decidability and finiteness. In the context of unification, Miller’s higher-order patterns have a single most general unifier. We relax the restrictions in his patterns without changing determinism within the context of matching instead of unification. As a consequence, the new class of patterns covers a wide class of useful patterns for program transformation. The time-complexity of the matching algorithm is linear for the size of a term for a fixed pattern.


Higher-order pattern matching Functional programming Program derivation Program transformation Fusion transformation 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. 1.
    Huet, G.P., Lang, B.: Proving and applying program transformations expressed with second-order patterns. Acta Informatica 11, 31–55 (1978)zbMATHCrossRefMathSciNetGoogle Scholar
  2. 2.
    de Moor, O., Sittampalam, G.: Higher-order matching for program transformation. Theoretical Computer Science 269, 135–162 (2001)zbMATHCrossRefMathSciNetGoogle Scholar
  3. 3.
    Krieg-Brückner, B., Liu, J., Shi, H., Wolff, B.: Towards correct, efficient and reusable transformational developments. In: Broy, M., Jähnichen, S. (eds.) KORSO 1995. LNCS, vol. 1009, pp. 270–284. Springer, Heidelberg (1995)CrossRefGoogle Scholar
  4. 4.
    Gill, A., Launchbury, J., Jones, S.L.P.: A short cut to deforestation. In: Proceedings of the 6th International Conference on Functional Programming Languages and Computer Architecture (FPCA 1993), Copenhagen, Denmark, pp. 223–232. ACM Press, New York (1993)CrossRefGoogle Scholar
  5. 5.
    Sheard, T., Launchbury, J.: Warm fusion: Deriving build-catas from recursive definitions. In: Conference on Functional Programming Languages and Computer Architecture, La Jolla, CA, USA, ACM, pp. 314–323. ACM, New York (1995)Google Scholar
  6. 6.
    Bird, R.: Introduction to Functional Programming using Haskell, 2nd edn. Prentice-Hall, Englewood Cliffs (1998)Google Scholar
  7. 7.
    Baxter, L.: The complexity of unification. PhD thesis, Department of Computer Science, University of Waterloo (1977)Google Scholar
  8. 8.
    Schubert, A.: Linear interpolation for the higher-order matching problem. In: Bidoit, M., Dauchet, M. (eds.) CAAP 1997, FASE 1997, and TAPSOFT 1997. LNCS, vol. 1214, pp. 441–452. Springer, Heidelberg (1997)CrossRefGoogle Scholar
  9. 9.
    Miller, D.: A logic programming language with lambda-abstraction, function variables, and simple unification. Journal of Logic and Computation 1, 497–536 (1991)zbMATHCrossRefMathSciNetGoogle Scholar
  10. 10.
    Nipkow, T.: Functional unification of higher-order patterns. In: 8th IEEE Symposium on Logic in Computer Science, pp. 64–74. IEEE Computer Society Press, Los Alamitos (1993)Google Scholar
  11. 11.
    Meijer, E., Fokkinga, M., Paterson, R.: Functional programming with bananas, lenses, envelopes and barbed wire. In: Hughes, J. (ed.) FPCA 1991. LNCS, vol. 523, pp. 124–144. Springer, Heidelberg (1991)Google Scholar
  12. 12.
    Sheard, T., Fegaras, L.: A fold for all seasons. In: Conference on Functional Programming Languages and Computer Architecture, pp. 233–242 (1993)Google Scholar
  13. 13.
    Heckmann, R.: A functional language for the specification of complex tree transformation. In: Ganzinger, H. (ed.) ESOP 1988. LNCS, vol. 300, pp. 175–190. Springer, Heidelberg (1988)Google Scholar
  14. 14.
    Sheard, T., Peyton Jones, S.L.: Template metaprogramming for Haskell. In: Haskell Workshop, Pittsburgh, Pennsylvania, pp. 1–16 (2002)Google Scholar
  15. 15.
    Hu, Z., Iwasaki, H., Takeichi, M., Takano, A.: Tupling calculation eliminates multiple data traversals. In: Proceedings of the 2nd ACM SIGPLAN International Conference on Functional Programming (ICFP 1997), Amsterdam, The Netherlands, pp. 164–175. ACM Press, New York (1997)CrossRefGoogle Scholar
  16. 16.
    Curien, R., Qian, Z., Shi, H.: Efficient second-order matching. In: Ganzinger, H. (ed.) RTA 1996. LNCS, vol. 1103, pp. 317–331. Springer, Heidelberg (1996)Google Scholar
  17. 17.
    Wierzbicki, T.: Complexity of the higher order matching. In: Ganzinger, H. (ed.) CADE 1999. LNCS (LNAI), vol. 1632, pp. 82–96. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  18. 18.
    Hirata, K., Yamada, K., Harao, M.: Tractable and intractable second-order matching problems. In: Asano, T., Imai, H., Lee, D.T., Nakano, S.-i., Tokuyama, T. (eds.) COCOON 1999. LNCS, vol. 1627, pp. 432–441. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  19. 19.
    Schmidt-Schauß, M., Stuber, J.: On the complexity of linear and stratified context matching problems. Rapport de Recherche RR-4923, Institut National de Recherche en Informatique et en Automatique (2003)Google Scholar
  20. 20.
    Guttmann, W., Partsch, H., Schulte, W., Vullinghs, T.: Tool support for the interactive derivation of formally correct functional programs. Journal of Universal Computer Science 9, 173–188 (2003)Google Scholar
  21. 21.
    Peyton Jones, S.L., Tolmach, A., Hoare, T.: Playing by the rules: rewriting as a practical optimisation technique in ghc. In: Haskell Workshop (2001)Google Scholar
  22. 22.
    Visser, E.: Stratego: A language for program transformation based on rewriting strategies. system description of stratego 0.5. In Middeldorp. In: Middeldorp, A. (ed.) RTA 2001. LNCS, vol. 2051, pp. 357–362. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  23. 23.
    Bauer, F., Ehler, H., Horsch, B., Möller, B., Partsch, H., Paukner, O., Pepper, P. (eds.): The Munich Project CIP. LNCS, vol. 292. Springer, Heidelberg (1988)Google Scholar
  24. 24.
    Taha, W., Sheard, T.: Multi-stage programming with explicit annotations. In: Proc. Conference on Partial Evaluation and Program Manipulation, Amsterdam, Amsterdam, pp. 203–217. ACM Press, New York (1997)Google Scholar
  25. 25.
    Tullsen, M., Hudak, P.: An intermediate meta-language for program transformation. Research report yaleu/dcs/rr-1154, Department of Computer Science, Yale University (1998)Google Scholar
  26. 26.
    de Moor, O., Sittampalam, G.: Generic program transformation. In: Swierstra, S.D., Oliveira, J.N. (eds.) AFP 1998. LNCS, vol. 1608, pp. 116–149. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  27. 27.
    Sittampalam, G.: Higher-order matching for program transformation. PhD thesis, University of Oxford (2001)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2004

Authors and Affiliations

  • Tetsuo Yokoyama
    • 1
  • Zhenjiang Hu
    • 1
    • 2
  • Masato Takeichi
    • 1
  1. 1.Department of Mathematical Informatics, Graduate School of Information Science and TechnologyUniversity of TokyoTokyoJapan
  2. 2.PRESTO21, Japan Science and Technology Agency 

Personalised recommendations