In ML~style pattern matching, pattern size is not constrained and ambiguous patterns are allowed. This generality leads to a clear and concise programming style but is challenging in the context of lazy evaluation. A first challenge concerns language designers: in lazy ML, the evaluation order of expressions follows actual data dependencies. That is, only the computations that are needed to produce the final result are performed. Once given a proper (that is, non-ambiguous) semantics, pattern matching should be compiled in a similar spirit: any value matching a given pattern should be recognized by performing only the minimal number of elementary tests needed to do so. This challenge was first met by A.~Laville. A second challenge concerns compiler designers. As it stands, Lavilles compilation algorithm cannot be incorporated in an actual lazy ML compiler for efficiency and completeness reasons. As a matter of fact, Lavilles original algorithm did not fully treat the case of integers in patterns and can lead to explosions both in compilation time and generated code size. This paper provides a complete solution to that second challenge. In particular, the well-known (and size-efficient) pattern matching compilation technique using backtracking automata is here introduced for the first time into the world of lazy pattern matching.
[1]
Simon L. Peyton Jones,et al.
The Implementation of Functional Programming Languages
,
1987
.
[2]
Xavier Leroy,et al.
The ZINC experiment : an economical implementation of the ML language
,
1990
.
[3]
Pierre-Louis Curien.
Categorical Combinators, Sequential Algorithms, and Functional Programming
,
1993,
Progress in Theoretical Computer Science.
[4]
Alain Laville.
Comparison of Priority Rules in Pattern Matching and Term Rewriting
,
1991,
J. Symb. Comput..
[5]
G.D. Plotkin,et al.
LCF Considered as a Programming Language
,
1977,
Theor. Comput. Sci..
[6]
Luc Maranget,et al.
GAML: a Parallel Implementation of Lazy ML
,
1991,
FPCA.