Abstract
In modern functional languages, pattern matching is used to define functions or expressions by performing an analysis of the structure of values. We extend Haskell with a new non-local form of patterns called context patterns, which allow the matching of subterms without fixed distance from the root of the whole term. The semantics of context patterns is defined by transforming them to standard Haskell programs. Typical applications of context patterns are functions which search a data structure and possibly transform it.
This concept can easily be adopted for other languages using pattern matching like ML or Clean.
Preview
Unable to display preview. Download preview PDF.
References
H. P. Barendregt. The Lambda Calculus: Its Syntax and Semantics, volume 103 of Studies in Logic and The Foundations of Mathematics. North-Holland, 1985.
T. Brus, M. van Ecklen, M. Van Leer, and M. Plasmeijer. Clean — A Language for Functional Graph Rewriting. In G. Kahn, editor, Proccedings of the 3rd Conference on Functional Programming Languages and Computer Architecture (FPCA), number 274 in Lecture Notes in Computer Science, pages 364–384. Springer-Verlag, September 1987.
D. J. Dougherty and P. Johann. A Combinatory Approach to Higher-Order ∧-Unification. Theoretical Computer Science, 139(1–2):207–242, March 1995.
P. Deransart and J. Maluszyński, editors. Proccedings of the 2nd International Workshop on Programming Language Implementation and Logic Programming (PLILP), number 456 in Lecture Notes in Computer Science. Springer-Verlag, 1990.
C. Ferdinand. Pattern Matching in a Functional Transformational Language using Treeparsing. In Deransart and Małuszyński [DM90], pages 358–371.
W. D. Goldfarb. The Undecidability of the Second-Order Unification Problem. Theoretical Computer Science, 13(2):225–230, February 1981.
R. Heckmann. A Functional Language for the Specification of Complex Tree Transformations. In H. Ganzinger, editor, Proccedings of the 2nd International Symposium on European Symposium on Programming (ESOP), number 300 in Lecture Notes in Computer Science, pages 175–190. Springer-Verlag, 1988.
P. Hudak and J. H. Fasel. A Gentle Introduction to Haskell. Technical report, Department of Computer Science, 1992.
M. Hanus, H. Kuchen, and J. J. Moreno-Navarro. Curry: A Truly Functional Logic Language. In Proc. ILPS'95 Workshop on Visions for the Future of Logic Programming, pages 95–107, 1995.
G. Huet and B. Lang. Proving and applying Program Transformations Expressed with Second Order Patterns. Acta Informatica, 11:31–55, 1978.
P. Hudak, S. L. Peyton Jones, and P. Wadler et. al. Report on the Programming Language Haskell — A Non-strict, Purely Functional Language. Research Report 1.2, Department of Computer Science and Department of Computing Science, March 1992.
G. Huet. A Unification Algorithm for Typed λ-Calculus. Theoretical Computer Science, 1:27–57, 1975.
R. J. M. Huges. A Novel Representation of Lists and Its Apllication to the Function “reverse”. Information Processing Letters, 22(3):141–144, March 1986.
H. Kuchen, R. Loogen, J.J. Moreno-Navarro, and M. Rodriguez-Artalejo. The Functional Logic Language BABEL and its Implementation on a Graph Machine. New Generation Computing, 14:391–427, 1996.
R. Milner. The standard ML core language. Dept Computer Science, University of Edinburgh, 1984.
M. Mohnen and S. Tobies. Implementing Context Patterns in the Glasgow Haskell Compiler. Technical Report AIB-97-04, RWTH Aachen, 1997. to be published.
M. Odersky and P. Wadler. Pizza into Java: Translating theory into Practice. In Proccedings of the 24th Symposium on Principles of Programming Languages (POPL), pages 146–159. ACM, January 1997.
S. L. Peyton Jones. The Implementation of Functional Programming Languages. Prentice-Hall, 1987.
S. L. Peyton Jones. Compiling Haskell by Program Transformations: A Report from the Trenches. In H. R. Nielson, editor, Proccedings of the 6th International Symposium on European Symposium on Programming (ESOP), number 1058 in LNCS, pages 18–44. Springer-Verlag, 1996.
C. Prehofer. Decidable Higher-order Unification Problems. In A. Bundy, editor, Proccedings of the 12th International Conference on Automated Deduction (CADE), number 814 in Lecture Notes in Computer Science, pages 635–649. Springer-Verlag, 1994.
S. L. Peyton Jones and A. Santos. Compilation by Transformation in the Glasgow Haskell Compiler. In Functional Programming, Glasgow 1994, Workshops in Computing. Springer-Verlag, 1994.
C. Queinnec. Compilation of Non-Linear, Second Order Patterns on S-Expressions. In Deransart and Małuszyński [DM90], pages 340–357.
W. Snyder and J. Gallier. Higher Order Unification Revisited: Complete Sets of Tranformations. Journal of Symbolic Computation, 8(1 & 2):101–140, 1989. Special issue on unification. Part two.
P. Thiemann. Avoiding repeated tests in pattern matching. In P. Cousot, M. Falaschi, G. Filè, and A. Rauzy, editors, Proccedings of the 3rd International Workshop on Static Analysis (WSA), number 724 in Lecture Notes in Computer Science, pages 141–152. Springer-Verlag, 1993.
R. Wilhelm. Tree Transformations, Functional Languages, and Attribute Grammars. In P. Deransart and M. Jourdan, editors, Attribute Grammars and their Applications, number 461 in LNCS, pages 116–129. Springer-Verlag, 1990.
Author information
Authors and Affiliations
Editor information
Rights and permissions
Copyright information
© 1997 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Mohnen, M. (1997). Context patterns in Haskell. In: Kluge, W. (eds) Implementation of Functional Languages. IFL 1996. Lecture Notes in Computer Science, vol 1268. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-63237-9_18
Download citation
DOI: https://doi.org/10.1007/3-540-63237-9_18
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-63237-5
Online ISBN: 978-3-540-69239-3
eBook Packages: Springer Book Archive