4 Compiling Pattern Matching by Term Decomposition

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

4 January1990
Publication Notes
Laurence Puel’s address is:Laboratoire d’Informatique LIENS URA CNRS1327,Ecole Normale Sup´e rieure,45rue d’Ulm,72230Paris C´e dex05,FRANCE.This article will also appear as the“Rapport de Recherche du LIENS90-7.”
c Digital Equipment Corporation an
d Ecol
e Normale Sup´erieure1991
This work may not be copied or reproduced in whole or in part for any commercial purpose.Permission to copy in whole or in part without payment of fee is granted for non-profit educational and research purposes provided that all such whole or partial copies include the following:a notice that such copying is by joint permission of the Paris Research Laboratory of Digital Equipment Centre Technique Europe (Rueil-Malmaison,France)and of the Laboratoire d’Informatique LIENS URA CNRS1327(Paris, France);an acknowledgement of the authors and individual contributors to the work;and all applicable portions of the copyright notice.All rights reserved.
ii
Abstract
We present a method for compiling pattern matching on lazy languages based on previous work by Laville and Huet-L´e vy.It consists of coding ambiguous linear sets of patterns using“Term Decomposition,”and producing non ambiguous sets over terms with structural constraints on variables.The method can also be applied to strict languages giving a match algorithm that includes only unavoidable tests when such an algorithm exists.
R´esum´e
Nous pr´e sentons une m´e thode de compilation de l’appel parfiltrage pour les langages paresseux dans le prolongement du travail de Laville et Huet-L´e vy.Nous transformons des ensembles ambigus de motifs lin´e aires`a l’aide de la“D´e composition des Termes”pour produire des ensembles non-ambigus de termes dont les variables sont munies de contraintes structurelles. Cette m´e thode peut aussiˆe tre appliqu´e e`a des langages stricts et donne un algorithme de filtrage ne n´e cessitant aucun travail inutile quand un telfiltrage existe.
iii
Keywords
Compilation,Call by Pattern Matching,Term Decomposition,Sequentiality
Acknowledgements
We are grateful to Jean-Jacques L´e vy who made numerous suggestions on the presentation of this work.We would like also to acknowledge helpful comments made by G´e rard Huet and Hassan A¨ıt-Kaci.
iv
Contents
1Introduction1
1.1Constrained Terms1
1.2Pattern Matching2
1.3Compilation2 2T erms and Constraints5
2.1Terms5
2.2Constraints6
2.3Constraint Simplification8
2.4Constrained Terms9
2.5Substitution10 3T erm Decomposition14
3.1Decomposition14
3.2Decomposition Procedure15
3.3Decomposition Normalization16 4Pattern Matching17
4.1Sequentiality19 5Examples22 6Conclusion24 References26
v
Compiling Pattern Matching by T erm Decomposition1
2Laurence Puel and Asc´ander Su´arez
Compiling Pattern Matching by T erm Decomposition3
4Laurence Puel and Asc´ander Su´arez
=
(...)= (1...)1...
and that if then≡.From those properties we deduce the following simplification rules that associate to each constraint an equivalent normal form where the term
in each atomic constraint is a variable:
Let1...be terms,1...be linear terms,be a set of linear terms and a variable.
(1...)(1...)≡(1)(1...)
()()≡
(1...)(...)≡(1...)

Ω≡
()≡


.As ≡or
=()is the mapping over constrained terms defined by
is admissible for.
Notice that when=the substitution
1=(11)and
2
=()unifies1and2if and only if
=((12))is a principal unifier for1and2.
4.Let=and=be two constrained terms(in fact the last one is a
pure term).if and only if and.
Proof:
1.12if and only if there exists
=(2)satisfies
of the terms:
=()(()(())
=(()())()
is defined by:
()=()
()=
()1where,for every ,
()1=()()(11())1,in order to prove the lemma,it is sufficient to prove the equivalence of the constraints()()and ()for every integers,such that.()()≡()if and only if for all substitution,()()if and only if().The if part is clear.Let us suppose that there exists such that()()and()=(). As and are unifiable with the m.g.u.,if()there exists a substitution such that()=().Thus()()that is a contradiction.Otherwise,let =∈()≠and()=.Notice that()=∅because and are unifiable.Thus()[∈]which is an instance of.Then,we conclude as in the previous case.
3.3Decomposition Normalization
It is useful to transform constraints into an easily readable shape and we propose now a normalization algorithm.Itsfirst step is to split these terms into terms with constraints with only one function symbol.Its second step is to normalize the constraint associated to a variable appearing at the same occurrence in two trees in the decomposition,in order to get the same constraint at common occurrences.
Definition11A decomposition=1...is in normal form if and only if:
1.Each constraint occurring in each,has only one symbol.
2.If there exist≠and an occurrence of and such that,for every prefix,
and have the same symbol at,=,=then,
=.
Normalization Algorithm Let1...be a set of constrained terms.
let=((1...)).If there exists non-variable:
((Ω...Ω))[(1...)]
If there exist and satisfying hypothesis2.above with(Ω...Ω)∈and ≠∅:
[(Ω...Ω)][(1...)] January1990Digital PRL
Compiling Pattern Matching by T erm Decomposition25
References
1.G.Berry.S´e quentialit´e de l’´e valuation formelle des lambda-expressions.In Proc.3rd
International Colloquium on Programming,Paris,March1978.Dunod.
2.R.Burstall,D.MacQueen,and D.Sannella.Hope:An experimental applicative language.
In Lisp and Functional programming conference,pages136–143.ACM,1980.
on.Unification et disunification.Th´e orie et applications.Th`e se,Institut National
Polytechnique de Grenoble,1988.
4.R.Harper,ner,and M.Tofte.The definition of Standard ML version2.LFCS
Report Series88-62,University of Edinburgh,Department of Computer science,The King’s Buildings,Edinburgh EH93JZ,Scotland,1988.
5.G.Huet and J.-J.L´e vy.Call by need computations in non ambiguous linear term rewriting
systems.Rapport IRIA Laboria359,INRIA,Domaine de V oluceau,Rocquencourt BP105, 78153Le Chesnay Cedex.FRANCE,1979.
ville.Evaluation paresseuse desfiltrages avec priorit´e.Application au Langage ML.
Th`e se,Universit´e Paris7,1988.
ville.Implementation of lazy pattern matching algorithms.In H.Ganzinger,editor,
ESOP’88,pages298–316.Lecture Notes in Computer Science300,March1988.
8.L.Puel.Bons pr´e ordres sur les arbres associ´e s`a des ensembles in´e vitables et preuves de
terminaison de syst`e mes de r´e´e criture.Th`e se d’Etat,Universit´e Paris7,1987.
9.L.Puel.Embedding with patterns and associated recursive path ordering.In N.Der-
showitz,editor,RTA,pages371–387.Lecture Notes in Computer Science355,April 1989.
10.P.Weis et al.The CAML reference manual.Available through INRIA,Domaine de
V oluceau,Rocquencourt BP105,78153Le Chesnay Cedex.FRANCE,January1989.
PRL Research Reports
Report Number1:Incremental Computation of Planar Maps.Michel Gangnet,Jean-Claude Herv´e,Thierry Pudet,and Jean-Manuel Van Thong.May1989.
Report Number2:BigNum:A Portable and Efficient Package for Arbitrary-Precision Arithmetic.Bernard Serpette,Jean Vuillemin,and Jean-Claude Herv´e.April1991.
Report Number3:Introduction to Programmable Active Memories.Patrice Bertin, Didier Roncin,and Jean Vuillemin.June1989.
Report Number4:Compiling Pattern Matching by Term urence Puel and Asc´ander Su´arez.January1990.
Report Number5:The WAM:A(Real)Tutorial.Hassan A¨ıt-Kaci.January1990.。

相关文档
最新文档