| L. Augustsson. Compiling pattern matching. In Proc. of the Conf. on Functional Programming Languages and Computer Architecture, LNCS 201, 1985. |
....intimate details of runtime issues such as the representation of values, compiler code is often better than human code, both as regards compactness and eciency. There are two approaches to pattern matching compilation, the underlying model being either decision trees [5] or backtracking automata [1]. Using decision trees, one produces a priori faster code (because each position in a term is tested at most once) while using backtracking automata, one produces a priori less code (because patterns never get copied, hence never get compiled more than once) The price paid in each case is ....
....p q is indeed the least upper bound of p and q is easy, by considering patterns as sets of their instances. Note that p q is de ned up to equivalence, and that it encodes instance intersection. 3. COMPILATION In this section, we present a compilation scheme close to the one described in [20, 1], and implemented in compilers such as the hbc compiler or the Objective Caml compiler. This classical scheme will be re ned later into an optimized scheme, using same notations and concepts. 3.1 Output of the match compiler The compilation of pattern matching is described by the scheme C that ....
[Article contains additional citation context not shown here]
Augustsson, L. Compiling pattern matching. In Functional Programming Languages and Computer Architecture, J.-P. Jouannaud, Ed. Springer-Verlag, Berlin, DE, 1985, pp. 368-381. Lecture Notes in Computer Science 201Proceedings of. Conference at Nancy.
.... c v 1 : v k This describes a first order language, with functions possibly involving the matching of a single simple pattern (i.e. only one constructor deep) Compilation to such a form requires only well known techniques, being essentially equivalent to compiling to simple case expressions [Aug85, Wad87a]. The key step is replacing a pattern match several constructors deep with a corresponding number of simple pattern matches, introducing appropriate new functions. The intended semantics is the usual normal order reduction of the lambda calculus. Pattern matching, however, is strict: when a ....
L. Augustsson, Compiling pattern matching. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture, Nancy, France, September 1985. LNCS 201, Springer-Verlag, 1985.
....in the example) profits maximally from the RC optimization; no space is consumed at all. Our code takes .77 seconds for Tree. In [Sch88] rewrite rules are translated into an abstraction of imperative programming languages; if then else structures. The algorithm is claimed to be very similar to [Aug85], but it is optimized with respect to the domain over which the function should be compiled. An interesting point is that the algorithm may give more efficient code when non free constructors are allowed. 6.2 Compilers mapping to an abstract machine The idea to use an abstract machine as an ....
Lennart Augustsson. Compiling pattern matching. In J.P. Jouannaud, editor, Functional Programming Languages and Computer Architecture, volume 201 of Lecture Notes in Computer Science, pages 368--381. Springer-Verlag, 1985.
....1 : t 1 ; p n : t n are called the branches. Function definitions have the form f v 1 : v k = t Example definitions are shown in Figure 1. The patterns in case terms may not be nested. Methods to transform case terms with nested patterns to ones without nested patterns are well known [1, 14]. The language is typed using the Hindley Milner polymorphic type system [8, 9, 5] found in LML and other languages; the reader is assumed to be familiar with this type system. Each constructor c and function f has a fixed arity k . For example, the constructor Nil has arity 0, the constructor ....
L. Augustsson, Compiling pattern matching. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture, Nancy, France, September 1985. LNCS 201, Springer-Verlag, 1985.
....This is done by storing the objects created into global variables once in the initialization phase of the Scheme program and references to these globals replace references to the constants. Constants not containing atoms get converted to Scheme constants. For example, the Erlang call f( 1,tWo] [3,4]) gets converted to: define const1 (string symbol tWo ) global definitions (define const2 (list 1 const1) f const2 (3 4) Alternative representations for atoms which were rejected are: Strings: no special treatment for uppercase letters is needed but the equality test is ....
....bound variables at each node and performs constant propagation and constant folding. Constant propagation and folding are mainly needed to avoid allocation of structures which are constant, such as in the definition f(X) Y= 1,2, X,Y,3,4] which gets compiled as though it were: f(X) X [ 1,2,3,4]] The list [ 1,2,3,4] is represented internally as the Scheme constant list (#(tuple 1 2) 3 4) Following this, the free variables before and after each node are computed. This is done as a separate pass because the bound variable analysis requires a leftto right traversal of the parse tree, ....
[Article contains additional citation context not shown here]
Lennart Augustsson. Compiling Pattern Matching. In Jean-Pierre Jouannaud, editor, Conference on Functional Programming Languages and Computer Architecture, Nancy, France, LNCS 201, pages 368--381. Springer Verlag, 1985.
....yield the same bindings. 6.2 Theorem [Soundness of Optimization] If A . D ) E and t 2 A, then 1. t 2 D i t 2 E; and 2. for all x, we have t 2 D ) x; u) i t 2 E ) x; u) 13 7 Related Work The pattern match compilation techniques used in functional language compilers [BM85, PS90, Aug85, Wad87, Ler91, Mar94] are complementary to our pattern optimization technique. The goal of pattern match compilers is to generate lower level code for a good order of traversal in the input tree, requires few run time checks, whereas our technique performs a higher level optimization on patterns ....
....variables and checks for satis ability of the constraints [AW92] or nds a locally minimal solution [GTT93] In their setting, globally minimal solutions (which are crucial for us) may not necessarily exist. Pattern match compilation for lazy functional languages raises some subtle issues [PS90, Aug85, Wad87, Mar94] that go beyond what we have considered here. 8 Conclusions and Future Work We have developed a series of analyses on pattern matching that are applicable to typed languages based on tree automata, with ML style pattern matching plus OR and recursive patterns. These analyses are ....
[Article contains additional citation context not shown here]
Lennart Augustsson. Compiling pattern matching. In Functional Programming Languages and Computer Architecture, volume 201 of Lecture Notes in Computer Science, pages 368-381. Springer Verlag, September 1985.
....12 7 Related Work A study on pattern matching compilation in ML can be found in (MacQueen and Baudinet 1985) where heuristics are presented for arranging tag checks so as to minimize the size of generated test trees. Also pattern matching compilation for lazy evaluation is studied in (Augustsson 1985; Laville 1988; Puel and Su arez 1993) Clearly, we can always use the methods presented in these studies to generate a test tree and then further prune the test tree with the method given in Section 4. Pattern matching with dependent types in MartinL of s type theory (Nordstr om, Petersson, and ....
Augustsson, L. (1985). Compiling Pattern Matching.
....datatypes. However, pattern matching is a high level concept that the compiler must transform into sequences of test operations. Patterns must be unnested to yield flat patterns which can then be implemented as constructor tests and selector operations. Methods to achieve this are well known [Aug85]. Nested patterns are often a subtle source of inefficiency. In their presence it is quite often the case that function arguments are partially known so that the patterns of successive calls overlap. But overlapping patterns cause redundant constructor tests for the overlapping part. For a ....
Lennart Augustsson. Compiling pattern matching. In Proc. Functional Programming Languages and Computer Architecture 1985, pages 368--381. Springer Verlag, 1985. LNCS 201.
....b reduces to q[e x] and to transform this to x: e; q. A key element here is that we want to dispense with runtime closures. We have to be careful though so that we do not introduce name conflicts. Given the definitions so far, the denotation for 1 (2 3) is: lr.lk.R[ 1] r le 1 .lk.R[ 2] r le 1 . R[[3]]r le 2 .k(e 1 e 2 ) le 2 .k(e 1 e 2 ) which, given an environment and a continuation lx.q, we would transform into: e 1 : 1; e 1 : 2; e 2 : 3; e 2 : e 1 e 2 ; x : e 1 e 2 ; q This is incorrect, since variables are overwritten over and over again. If we assume that all ....
....is ready to be compiled to Scheme. Most importantly, pattern matching constructs must be transformed to the appropriate tests and component extractions. The first implementation of DML used the traditional method of compiling pattern matching constructs, which is well described by Augustsson 1985 [3] and Wadler 1987 [26] Recently, the DML implementation was improved by replacing this with a new, more efficient pattern match compilation method by Pettersson, 19] 5.4 Compiler Generation When the transformations above have been applied, code generation to Scheme is a simple matter of ....
Lennart Augustsson. Compiling pattern-matching. In Proceedings of the 1985 Conference on Functional Programming Languages and Computer Architecture, LNCS-201. Springer-Verlag, 1985.
....able to return the following customized induction theorem, which contains the full cases: 8P. P(0, 8h t. P(0, h: t) 8n. P(Suc n, 8n h t. P(n,t) Gamma P (Suc n, h: t) Gamma v w. P(v,w) This is only possible because we have altered the standard pattern matching algorithm [Aug85] so that, instead of just returning a nested case expression (its usual functionality) it generates the complete set of patterns for the type the function is being defined over. With this induction theorem, proofs of inductive properties of nth are possible. Thus underspecification for ....
Lennart Augustsson. Compiling pattern matching. In J.P. Jouannnaud, editor, Conference on Functional Programming Languages and Computer Architecture (LNCS 201), pages 368--381, Nancy, France, 1985.
....When ML is given strict semantics, as in SML [7] all orders are correct and choosing a particular order is only a matter of code size and run time efficiency. When ML is given lazy INRIA Rocquencourt. This work was partially funded by DRET under grant N o 8780814. 0 semantics, as inz LML [1], all testing orders are not semantically equivalent. Consider for instance the ML definition: let F x y = match (x; y) with (true; true) 1 ( false) 2 (false; true) 3 Patterns can be checked from left to right, as it is usually the case (function F 1 , below) or from right to left ....
....of lemma 2.3, two patterns are compatible if and only if they admit a common instance. 3 Compilation Pattern matching is modeled as a function over the set of partial values. This function is compiled into multiway branches represented by simple pattern matching expressions, in the spirit of [1]. 3.1 The matching function Pattern matching is usually formalized as a predicate on partial values [2, 5] We prefer a representation as a function over partial values, closer to pattern matching in ML. A clause is a three tuple (i; p; e) where i is an integer, p is a pattern and e is a ....
[Article contains additional citation context not shown here]
L. Augustsson, "Compiling pattern matching". FPCA'85.
....a KMP style string matcher from a general naive matcher, using a specializer with positive and negative information, but without a theorem prover. Match compilation: Augustsson described a top down, left right compilation algorithm for ML style pattern matching in lazy functional languages [1]; see also Wadler s exposition in [16, Chapter 5] It does not naturally discover inexhaustive matches and redundant cases. In a lazy language, the order of testing of subterms affects evaluation order and hence termination, so terms are usually tested from top down and left right for simplicity ....
L. Augustsson. Compiling pattern matching. In Jean-Pierre Jouannaud, editor, Functional Programming Languages and Computer Architecture, Nancy, France, September 1985. (Lecture Notes in Computer Science, vol. 201), pages 368--381. Springer-Verlag, 1985.
....Tofte Author s address: L. Maranget, INRIA Rocquencourt, BP 105, 78153 Le Chesnay Cedex, France. Luc.Maranget inria.fr. 2 Luc Maranget 1991] all orders are correct, and choosing a particular order is only a matter of code size and run time e ciency. When ML is given lazy semantics, as in LML [Augustsson 1985], all testing orders are not semantically equivalent. Consider for instance the ML de nition: let F x y = match (x; y) with (true; true) 1 ( false) 2 (false; true) 3 The patterns can be checked from left to right, as it is usually the case (function F 1 , below) or from right to ....
....though, that compilers as mature as SML NJ [Appel and MacQueen 1991; Baudinet and MacQueen 1986] and Caml V3.1 [Weis 1990] use a similar compilation technique. Nevertheless, there already exists a di erent kind of automata for implementing pattern matching, such automata are the targets of the LML [Augustsson 1985] and Caml Light [Leroy 1995; Leroy 1990] compilers. One salient feature of these automata is a backtracking construct. Standard pattern matching compilation schemes rely on it to guarantee that the size of output automaton is linear in the size of the input program. The main contribution of the ....
[Article contains additional citation context not shown here]
Augustsson, L. 1985. Compiling pattern matching. In J.-P. Jouannaud (Ed.), Functional Programming Languages and Computer Architecture, pp. 368-381. Springer-Verlag. Lecture Notes in Computer Science 201.
....matching expression does not specify the order in which tests are performed. When ML is given strict semantics, as in SML [Milner et al. 1991] all orders are correct, and choosing a particular order is only a matter of code size and run time efficiency. When ML is given lazy semantics, as in LML [Augustsson, 1985], all testing orders are not semantically equivalent. Consider for instance the ML definition: let F x y = match (x; y) with (true; true) 1 ( false) 2 (false; true) 3 The patterns can be checked from left to right, as it is usually the case (function F 1 , below) or from right to ....
....One has to notice though, that compilers as mature as SML NJ [Appel and Macqueen, 1991] and Caml V3.1 [Weis, 1990] use a similar compilation technique. Nevertheless, there already exists a different kind of automata for implementing pattern matching, such automata are the targets of the LML [Augustsson, 1985] and Caml Light [Leroy et al. 1993, Leroy, 1990] compilers. One salient feature of these automata is a backtracking construct. Standard pattern matching compilation schemes rely on it to guarantee that the size of output automaton is linear in the size of the input program. The main contribution ....
L. Augustsson, "Compiling pattern matching". Conference Functional Programming and Computer Architecture 1985.
....2; 3g f1; 2; 3g f1; 2; 3g 6= b f1g 1 f2; 3g Figure 1: Left to right (left) and adaptive automata (right) for f(x; a; b) f(b; a; a) f(x; a; y) with textual order priority. Here x and y denote variables. Pattern matching automata have been extensively studied for well over a decade. Augustsson [1] and Wadler [14] describe pattern matching techniques based on left to right traversal. A drawback with these methods is that they may reexamine symbols potentially several times; so in the worst case they may end up testing each pattern separately against the input term. This drawback is overcome ....
L. Augustsson, Compiling Pattern Matching, FPCA '85, LNCS 201.
....our discussion, we will make choices which depend of the particular idiosyncrasies of the G machine. The algorithm described at the end of this paper is used in a compiler for Lazy ML, LML for short, developed by L. Augustsson and myself. Further details on the compiler can be found in the papers [Aug84, Joh84, Aug85]. 2 Different strategies for the transformation 2.1 Attempt 1: Translate everything into lambda expressions In dealing with programs containing lambda expressions, each lambda expression could be lifted out to become a global function (rewrite rule) In what follows x.y.e is treated as B one ....
L. Augustsson. Compiling Pattern Matching. In Proceedings 1985 Conference on Functional Programming Languages and Computer Architecture, pages 368-- 381, Nancy, France, 1985.
....: mg) c) p j v 0 (w 0 j v 0 ) f i fn f j ) 3. The function name ordering ( fn ) introduced in 2(c) must not be cyclic. Condition (1) states that the first parameter of each T0 function is a recursion parameter whose pattern p has at most a single constructor (cf. simple pattern of [1]) Condition (2a) states that the other non recursion parameters (namely v 1 ; vn) of the function are non accumulating with either variables or constants for the recursive calls C 1 ; C k . Note that no new variables are introduced. Condition (2b) ensures that the corresponding ....
....f (v,x,y) f(v,y,x) Even the fibonacci function given earlier does not satisfy the T0 form because of its use of the complex pattern n 2 in the third equation. However, we could make use of the pattern matching compilation technique of Augustsson [1] to obtain the following T0 definition. fib 0 = 1; fib (n 1) fib (n) fib 0 = 1; fib (n 1) fib n) fib n) This technique can be considered as a pre processing step to obtain more T0 functions for tupling transformations. A number of such pre preprocessing techniques are highlighted in ....
Lennart Augustsson. Compilingpattern-matching. In Conference on Functional Programming and Computer Architecture, pages 368--381, Nancy, France, Springer-Verlag LNCS
....machines; such implementations have been notoriously lacking. The Lazy ML (or LML for short) compiler project, pursued by Lennart Augustsson and myself, is an attempt to remedy the situation. Earlier papers have described some of the techniques used in this compiler: see [Aug84] Joh84] Aug85] and [Joh85] Figure 1 shows the structure of the compiler. LML source Parsing, type checking Tree Pattern matching transformation Tree, complex patterns removed Lambda lifting Tree, Recursive equations G code generation G machine code Target code generation VAX ....
....Figure 1: The Lazy ML compiler. In LML pattern matching is the primitive for scrutinizing values of concrete data types, both user defined and predefined ones (e.g. integers and lists) After parsing and type checking the compiler transforms pattern matching into simple case expressions; see [Aug85] The program is then transformed into a set of global recursive functions, reminiscent of super combinators [Hug82] This transformation is called lambda lifting and is described in [Joh85] Then each of the global functions are compiled into G machine code. The G machine is the abstract ....
[Article contains additional citation context not shown here]
L. Augustsson. Compiling Pattern Matching. In Proceedings 1985 Conference on Functional Programming Languages and Computer Architecture, pages 368--381, Nancy, France, 1985.
....procedure calls, infix operators to function applications, n tuple manipulations (making and selection) into family of primitive functions, removing n tuples from function arguments and block bindings etc. Literature has standard techniques to translate pattern matching into nested conditionals [10, 11, 15] as well. Thus, our task of static type analysis is greatly simplified after these transformations 12 . The kernel language description has been revised extensively by Ariola and Arvind in [4] There the reader will find precise operational dynamic semantics and proofs of confluence etc. We will ....
Lennart Augustsson. Compiling Pattern Matching. In Proceedings of the 1985 Workshop on Implementations of Functional Languages, Goteborg, Sweden. Chalmers University of Technology, February 1985.
....status. Abstractly, the first series of tests changes the statuses in either 0 or N statuses, while the second series checks if there are still messages pending on names with status. We are still investigating on how to organize these tests efficiently without producing too much code (see [2, 10] for a discussion of the size of such code in the context of compiling ML pattern matching) By contrast, when status is 100 and that a message arrives on get or add, then the corresponding matching is known immediately and the message pending on S is consumed. Then, the queue for S is known to be ....
L. Augustsson. Compiling pattern matching. In Proc. of the ACM Functional Programming and Computer Architecture Conference, 1985.
....It transforms out some of the syntactic constructs of the language that can be expressed in terms of other simpler constructs. The process of desugaring is often described as a source to source transformation [HMM86, Pey87] Examples of such transformations are compilation of pattern matching [Aug85, Wad87] compilation of list comprehensions [Aug87, Pey87] compilation of overloading [PJ93, Aug93] ffl another way in which program transformation is used during the compilation process occurs when the program needs to be transformed in order to be compiled using a given implementation ....
Lennart Augustsson. Compiling pattern matching. In Functional Programming Languages and Computer Architecture [Fun85], pages 368 -- 381.
....to this scheme is possible The G machine is a convenient abstraction for expressing these improved compilation scheme. An overview of the techniques used in our compiler for Lazy ML can be found in [Aug84] and [AJ89b] the compilation of pattern matching into efficient code is described in [Aug85]. Our method of lambda lifting is described in [Joh85, Joh87] and the Gmachine is described in [Joh84] The approach to machine code generation used in the LML compiler is described in [Joh86] Parallel computers, consisting of many (dozens, hundreds, or thousands) processors connected to either ....
L. Augustsson. Compiling Pattern Matching. In Proceedings 1985 Conference on Functional Programming Languages and Computer Architecture, Nancy, France, 1985.
....the following customized induction theorem, which contains the full cases: 8P. P(0, 8n. P(Suc n, 8h t. P(0, h: t) 8n h t. P(n,t) Gamma P (Suc n, h: t) Gamma 8v w. P(v,w) This is only possible because TFL contains an adaptation of a standard pattern matching algorithm [15], which generates the complete set of patterns for the type the function is being defined over, as well as returning a nested case expression (its usual functionality) With this induction theorem, proofs of inductive properties of nth are easy, for example the following theorem: 8n l. n length l ....
Lennart Augustsson. Compiling pattern matching. In J.P. Jouannnaud, editor, Conference on Functional Programming Languages and Computer Architecture (LNCS 201), pages 368--381, Nancy, France, 1985.
....X En 1 end prog : f 1(X1) E1 ; f n (Xn ) En program Figure 4: Expressions c; d constructors ff; fi type variables U ; V : P j U union type j R P ; Q : cfU g prime type R : ff cs remainder j 1 cs j 0 Figure 5: Types expressions. Algorithms to do this are well known [Aug85, Wad87]. ffl Case expressions always have a default alternative, of the form X E . A special form of this is used to indicate that the alternative should never be taken: X empty(X ) where empty is a built in function which always fails. ffl Interprocess communication is omitted for now. We ....
....when the inferred type is large and complicated. We intend to explore this problem as future work. 9.3 Pattern Matching In order to typecheck the full Erlang language, we must compile the pattern matching into simple case expressions. Standard algorithms exist to perform this transformation [Aug85, Wad87]. In most cases, the use of pattern matching compilation in our type checker is transparent to the programmer, but there are cases where unexpected types are derived. For example, one possible way to write the boolean and function is as follows: and(true,true) true; and(false,X) false; ....
L. Augustsson. Compiling pattern matching. In Functional Programming Languages and Computer Architecture, number 201 in Lecture Notes in Computing Science, pages 368 -- 381, Nancy, September 1985. Springer-Verlag.
....1) if n 0 viewout Zero = 0 viewout (Succ n) n 1 The function viewin has type int viewtype and the function viewout has type viewtype int . A function definition such as power or fib is translated in two steps. First, all pattern matching is translated into case expressions; see [Aug85, Wad87]. Second, calls of viewin and viewout are inserted at appropriate places. For example, the fib definition above is equivalent to: fib m = case viewin m of Zero ) viewout Zero Succ m 0 ) case viewin m 0 of Zero ) viewout (Succ (viewout Zero) Succ n ) fib n fib (viewout (Succ n) Note ....
L. Augustsson. Compiling pattern matching. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture, SpringerVerlag, September 1985.
No context found.
L. Augustsson. Compiling pattern matching. In Proc. of the Conf. on Functional Programming Languages and Computer Architecture, LNCS 201, 1985.
No context found.
Augustsson, L. (1985). Compiling Pattern Matching. In Jouannaud, J.-P., editor, Functional Programming Languages and Computer Architecture, pages 368--381, Berlin. Springer-Verlag LNCS 201.
No context found.
Augustsson, L. (1985). Compiling Pattern Matching. In J.-P. Jouannaud (Ed.), Functional Programming Languages and Computer Architecture, Berlin, pp. 368--381. Springer-Verlag LNCS 201.
No context found.
L. Augustsson. Compiling pattern matching. In J.-P. Jouannaud, editor, Functional Programming Languages and Computer Architecture, pages 368-381. Springer-Verlag, Berlin, DE, 1985.
No context found.
Lennart Augustsson. Compiling pattern matching. In J.P. Jouannaud, editor, Functional Programming Languages and Computer Architecture, volume 201 of Lecture Notes in Computer Science, pages 368-381. Springer-Verlag, 1985.
No context found.
L. Augustsson. Compiling Pattern Matching. In Conference Functional Programming and Computer Architecture, 1985.
No context found.
Lennart Augustsson. Compiling pattern matching. In J.P. Jouannaud, editor, Functional Programming Languages and Computer Architecture, volume 201 of Lecture Notes in Computer Science, pages 368--381. Springer-Verlag, 1985.
No context found.
Lennart Augustsson. Compiling Pattern Matching. In Conference Funcitonal Programming and Computer Architecture, 1985.
No context found.
L. Augustsson, "Compiling pattern matching", Functional Programming Languages and Computer Architecture, J-P. Jouannaud, Ed. , Lecture Notes in Computer Science, Vol 201, Springer-Verlag, Berlin, 1985, pp. 368-381.
Online articles have much greater impact More about CiteSeer.IST Add search form to your site Submit documents Feedback
CiteSeer.IST - Copyright Penn State and NEC