## Design and implementation of deterministic higher-order patterns (2005)

Citations: | 1 - 1 self |

### BibTeX

@MISC{Yokoyama05designand,

author = {Tetsuo Yokoyama and Zhenjiang Hu and Masato Takeichi},

title = {Design and implementation of deterministic higher-order patterns },

year = {2005}

}

### OpenURL

### Abstract

We introduce a class of deterministic higher-order patterns to Template Haskell for supporting declarative transformational programming with more elegant binding of pattern variables. Higher-order patterns are capable of checking and binding subtrees far from the root, which is useful for program manipulation. However, there are three major problems. First, it is difficult to explain why a particular desired matching result cannot be obtained because of the complicated higherorder matching algorithm. Second, the general higher-order matching algorithm is of high cost, which may be exponential time at worst. Third, the (possibly infinite) nondeterministic solutions of higher-order matching prevents it from being used in a functional setting. To resolve these problems, we impose reasonable restrictions on higher-order patterns to gain predictability, efficiency and determinism. We show that our deterministic higher-order patterns are powerful to support concise specification and efficient implementation of various kinds of program transformations for optimizations.

### Citations

536 |
The Implementation of Functional Programming Languages
- Jones
- 1987
(Show Context)
Citation Context ...ur pattern uses ErrorT monad and the failure can be propagated, and are the expression itself and thus are first-class objects. Some calculi introduces explicit failure constructs and capture of them =-=[20, 11]-=-. Domain-specific language in meta-programming is a promising approach [5]. Among functional meta-programming languages, i.e., Template Haskell [23], MetaML [15], and MetaOCaml [4, 16], only Template ... |

233 | Monad Transformers and Modular Interpreters
- Liang, Hudak, et al.
- 1995
(Show Context)
Citation Context ... This is important since we use the outer Q monad for generating new names and the inner monad for representing code. Here, the function liftY :: Q a -> Y a liftY = lift . lift is a monad transformer =-=[14]-=-, where the first lift transforms Q monad into ErrorT String Q monad which is lifted into Y monad by the second lift. The outer Q is wrapped in Y monad. The both two Q monads are merged by runY when w... |

172 | Template meta-programming for Haskell
- Sheard, Jones
- 2002
(Show Context)
Citation Context ...tern in the sense that the pattern variable g’ appears in the function position and will be bound to a function value. In this paper, we introduce a class of higher-order patterns to Template Haskell =-=[23]-=- for supporting declarative transformational programming with more elegant binding of pattern variables. Though the general higher-order patterns are capable of checking and binding subtrees far from ... |

147 |
Proving and applying program transformations expressed with second-order patterns
- Huet, Lang
- 1978
(Show Context)
Citation Context ... passed as parameters, or constructed from the smaller components. To overcome the first limitation so that the programmer can specify a region arbitrarily far from the root satisfying some condition =-=[9, 10]-=-, we extend the simple patterns with function variables, i.e., higher-order patterns. Recall the higher-order pattern g’ x (f y) in the introduction where g’ is a function variable. This higher-order ... |

141 | Views: a way for pattern matching to cohabit with data abstraction
- Wadler
- 1987
(Show Context)
Citation Context ...d a nondeterministic one (N-TrafoLa). Our approach is similar to D-TrafoLa. Wadler proposes views that enables pattern matching on abstract data types by user supplied isomorphic mapping between them =-=[28]-=-. The descendant version of views are [3, 19]. Similar mechanism called laws allows pattern matching with non-free algebraic data types [24]. We take no account for this aspect in this paper. Fahndric... |

132 | Stratego: A language for program transformation based on rewriting strategies. System description of Stratego 0.5
- Visser
- 2001
(Show Context)
Citation Context ...rm, higher-order patterns in MAG cover our patterns and many calculations can be written concisely. Stratego is a domain-specific language for writing term rewriting system for program transformation =-=[26]-=-. Almost all the program transformation systems adopt CUI. Notable exception includes Ultra, an interactive program transformation system which has visual interface [8]. 5 Conclusion and Future Work W... |

56 | T.: Playing by the rules: Rewriting as a practical optimisation technique
- Jones, Tolmach, et al.
- 2001
(Show Context)
Citation Context ...on In Glasgow Haskell Compiler (GHC), programmers can write rewrite rules as a part of the source program (in a pragma), suggesting the compiler to optimize the code wherever it can apply these rules =-=[21]-=-. Here is an example. map f [] = [] map f (x:xs) = f x : map f xs {-# RULES "map/map" forall f g xs. map f (map g xs) = map (f.g) xs #-} The first two lines define the familiar map function. The RULES... |

46 | Implementing multi-stage languages using ASTs, gensym, and reflection
- Calcagno, Taha, et al.
- 2003
(Show Context)
Citation Context ...apture of them [20, 11]. Domain-specific language in meta-programming is a promising approach [5]. Among functional meta-programming languages, i.e., Template Haskell [23], MetaML [15], and MetaOCaml =-=[4, 16]-=-, only Template Haskell provides a way to construct and pattern match with abstract syntax trees. In the others, the code fragments can not contain unbound variables. This is matched with our aim; we ... |

30 | G.: Generic program transformation
- Moor, Sittampalam
- 1998
(Show Context)
Citation Context ...ry we provide is program transformation. There are known to be many transformation systems. TrafoLa [9] and KORSO [12] are the functional transformation systems with kind of higherorder patterns. MAG =-=[6]-=- is higher-order term rewriting system for automatic application of promotion. Although they produce nondeterministic matches and the matching algorithm is not linear to the given term, higher-order p... |

28 |
Pattern Matching with Abstract Data Types
- Burton, Cameron
- 1993
(Show Context)
Citation Context ...approach is similar to D-TrafoLa. Wadler proposes views that enables pattern matching on abstract data types by user supplied isomorphic mapping between them [28]. The descendant version of views are =-=[3, 19]-=-. Similar mechanism called laws allows pattern matching with non-free algebraic data types [24]. We take no account for this aspect in this paper. Fahndrich and Boyland make a pattern like function wi... |

25 | Concatenate, reverse and map vanish for free
- Voigtländer
- 2002
(Show Context)
Citation Context ...pts simple patterns in the rule specification, uses a trivial rule application strategy on the program, disallows side conditions, and therefore needs little extra compilation time. It has been shown =-=[21, 13, 27]-=- that such RULES pragmas can be successfully applied to implement optimizations from simple rules like “map/map” to complex rules like partial evaluation or the shortcut fusion. Being simple, the RULE... |

19 |
The Complexity of Unification
- Baxter
- 1976
(Show Context)
Citation Context ... of a pattern is the maximum order of free variables occurring in it. The pattern is called higherorder if the order is more than one. Generally, the higher-order matching problem is at least NP-hard =-=[1]-=-. We impose restrictions on the higher-order patterns to obtain matches in linear time. Before explaining the restrictions, we prepare the necessary definitions. The head of an expression is the expre... |

17 | First class patterns
- Tullsen
- 2000
(Show Context)
Citation Context ...n this paper. Fahndrich and Boyland make a pattern like function with which one can define recursive patterns, alternative patterns, and so on [7]. Tullsen makes patterns functions of type a->Maybe b =-=[25]-=-. Therefore, patterns are first-class as well as functions. He specifies combinators for constructing patterns. He uses Maybe monad and its generalization MonadPlus monad to handle failures explicitly... |

15 |
A new look at pattern matching in abstract data types
- Gostanza, Peña, et al.
- 1996
(Show Context)
Citation Context ...approach is similar to D-TrafoLa. Wadler proposes views that enables pattern matching on abstract data types by user supplied isomorphic mapping between them [28]. The descendant version of views are =-=[3, 19]-=-. Similar mechanism called laws allows pattern matching with non-free algebraic data types [24]. We take no account for this aspect in this paper. Fahndrich and Boyland make a pattern like function wi... |

13 | Statically checkable pattern abstractions
- Fähndrich, Boyland
- 1997
(Show Context)
Citation Context ...aic data types [24]. We take no account for this aspect in this paper. Fahndrich and Boyland make a pattern like function with which one can define recursive patterns, alternative patterns, and so on =-=[7]-=-. Tullsen makes patterns functions of type a->Maybe b [25]. Therefore, patterns are first-class as well as functions. He specifies combinators for constructing patterns. He uses Maybe monad and its ge... |

13 |
A Functional Language for the Specification of Complex Tree Transformations
- Heckmann
- 1988
(Show Context)
Citation Context ... passed as parameters, or constructed from the smaller components. To overcome the first limitation so that the programmer can specify a region arbitrarily far from the root satisfying some condition =-=[9, 10]-=-, we extend the simple patterns with function variables, i.e., higher-order patterns. Recall the higher-order pattern g’ x (f y) in the introduction where g’ is a function variable. This higher-order ... |

9 | Context patterns in Haskell
- Mohnen
- 1996
(Show Context)
Citation Context ...Sum Problem, (8)Calculation of numerical expression, and so forth. They have all been tested on GHC 6.4.s4 Related Works Mohnen introduces restricted higher-order patterns, so called context patterns =-=[17]-=- into Haskell, and in the sequence paper to remove unnecessary repeated traversing he introduces extended context [18]. Heckmann introduces a special constant ’@’ which means a kind of hole of the con... |

8 |
Towards correct, efficient and reusable transformational developments
- Krieg-Bruckner, Liu, et al.
- 1995
(Show Context)
Citation Context ... trees before passing it to compiler. The supposed application of the combinator library we provide is program transformation. There are known to be many transformation systems. TrafoLa [9] and KORSO =-=[12]-=- are the functional transformation systems with kind of higherorder patterns. MAG [6] is higher-order term rewriting system for automatic application of promotion. Although they produce nondeterminist... |

6 | Lawful functions and program verification - Thompson - 1990 |

5 | T.: Tool support for the interactive derivation of formally correct functional programs
- Guttmann, Partsch, et al.
- 2003
(Show Context)
Citation Context ...tem for program transformation [26]. Almost all the program transformation systems adopt CUI. Notable exception includes Ultra, an interactive program transformation system which has visual interface =-=[8]-=-. 5 Conclusion and Future Work We define a class of deterministic higher-order patterns which cover a wide class of important patterns in program transformation. For those other than deterministic pa... |

5 |
Basic Pattern Matching Calculi: A Fresh View on Matching Failure
- Kahl
- 2004
(Show Context)
Citation Context ...ur pattern uses ErrorT monad and the failure can be propagated, and are the expression itself and thus are first-class objects. Some calculi introduces explicit failure constructs and capture of them =-=[20, 11]-=-. Domain-specific language in meta-programming is a promising approach [5]. Among functional meta-programming languages, i.e., Template Haskell [23], MetaML [15], and MetaOCaml [4, 16], only Template ... |

2 | Context patterns, part ii
- Mohnen
- 1997
(Show Context)
Citation Context ...ks Mohnen introduces restricted higher-order patterns, so called context patterns [17] into Haskell, and in the sequence paper to remove unnecessary repeated traversing he introduces extended context =-=[18]-=-. Heckmann introduces a special constant ’@’ which means a kind of hole of the context, and thus the matching becomes nondeterministic [9]. This pattern is implemented in TrafoLa, which are divided in... |

1 |
Zip fusion with hyperfunctions. available at http://www.cse.ogi.edu/ krstic/folds.pdf
- Launchbury, Krstic, et al.
- 2000
(Show Context)
Citation Context ...pts simple patterns in the rule specification, uses a trivial rule application strategy on the program, disallows side conditions, and therefore needs little extra compilation time. It has been shown =-=[21, 13, 27]-=- that such RULES pragmas can be successfully applied to implement optimizations from simple rules like “map/map” to complex rules like partial evaluation or the shortcut fusion. Being simple, the RULE... |

1 |
Available online from http://www.cse.ogi.edu/PacSoft/projects/metaml/index.html
- MetaML
- 2000
(Show Context)
Citation Context ...ure constructs and capture of them [20, 11]. Domain-specific language in meta-programming is a promising approach [5]. Among functional meta-programming languages, i.e., Template Haskell [23], MetaML =-=[15]-=-, and MetaOCaml [4, 16], only Template Haskell provides a way to construct and pattern match with abstract syntax trees. In the others, the code fragments can not contain unbound variables. This is ma... |

1 | Deterministic second-order patterns. Information Processing - Yokoyama, Hu, et al. - 2004 |