skip to main content
10.1145/2678015.2682539acmconferencesArticle/Chapter ViewAbstractPublication PagespepmConference Proceedingsconference-collections
research-article

Generalising Tree Traversals to DAGs: Exploiting Sharing without the Pain

Published: 13 January 2015 Publication History

Abstract

We present a recursion scheme based on attribute grammars that can be transparently applied to trees and acyclic graphs. Our recursion scheme allows the programmer to implement a tree traversal and then apply it to compact graph representations of trees instead. The resulting graph traversals avoid recomputation of intermediate results for shared nodes -- even if intermediate results are used in different contexts. Consequently, this approach leads to asymptotic speedup proportional to the compression provided by the graph representation. In general, however, this sharing of intermediate results is not sound. Therefore, we complement our implementation of the recursion scheme with a number of correspondence theorems that ensure soundness for various classes of traversals. We illustrate the practical applicability of the implementation as well as the complementing theory with a number of examples.

References

[1]
M. Abbott, T. Altenkirch, and N. Ghani. Categories of containers. In FoSSaCS, 2003.
[2]
A. V. Aho, R. Sethi, and J. D. Ullman. Compilers: principles, techniques, and tools. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, USA, 1986. ISBN 0--201--10088--6.
[3]
S. Anantharaman, P. Narendran, and M. Rusinowitch. Closure properties and decision problems of dag automata. Inf. Process. Lett., 94(5): 231--240, 2005.
[4]
E. Axelsson. Functional Programming Enabling Flexible Hardware Design at Low Levels of Abstraction. PhD thesis, Chalmers University of Technology, 2008.
[5]
P. Bahr. Modular tree automata. In MPC, 2012.
[6]
P. Bahr and E. Axelsson. Generalising Tree Traversals to DAGs: Exploiting Sharing without the Pain. Available from authors' web site, 2014. Technical report with full proofs.
[7]
P. Bahr and L. E. Day. Programming macro tree transducers. In WGP, 2013.
[8]
R. Bird. Using circular programs to eliminate multiple traversals of data. Acta Inform., 21(3):239--250, 1984.
[9]
R. Bird, J. Gibbons, S. Mehner, J. Voigtländer, and T. Schrijvers. Understanding idiomatic traversals backwards and forwards. In Haskell, 2013.
[10]
P. Buneman, M. Fernandez, and D. Suciu. UnQL: a query language and algebra for semistructured data based on structural recursion. The VLDB Journal, 9(1):76--110, 2000.
[11]
W. Charatonik. Automata on DAG representations of finite trees. Research report, Max-Planck-Institut für Informatik, March 1999.
[12]
A. Chlipala. Parametric higher-order abstract syntax for mechanized semantics. In ICFP, 2008.
[13]
R. A. Eisenberg, D. Vytiniotis, S. Peyton Jones, and S. Weirich. Closed type families with overlapping equations. In POPL, 2014.
[14]
J. Engelfriet. Bottom-up and top-down tree transformations -- a comparison. Mathematical systems theory, 9(2):198--231, 1975.
[15]
J. Engelfriet and H. Vogler. Macro tree transducers. J. Comput. System Sci., 31(1):71--146, 1985.
[16]
B. Fila and S. Anantharaman. Running tree automata on trees and/or dags. Technical report, LIFO, 2006.
[17]
J. Fokker and S. D. Swierstra. Abstract interpretation of functional programs using an attribute grammar system. In LDTA, 2009.
[18]
A. Fujiyoshi. Recognition of directed acyclic graphs by spanning tree automata. Theor. Comput. Sci., 411(38-39):3493--3506, 2010.
[19]
Z. Fülöp and H. Vogler. Syntax-Directed Semantics: Formal Models Based on Tree Transducers. Springer-Verlag New York, Inc., 1998.
[20]
A. Gill. Type-safe observable sharing in Haskell. In Haskell, 2009.
[21]
I. Hasuo, B. Jacobs, and T. Uustalu. Categorical views on computations on trees (extended abstract). In ICALP, 2007.
[22]
P. Johann and N. Ghani. Foundations for structured programming with GADTs. In POPL, 2008.
[23]
T. Kamimura and G. Slutzki. Transductions of dags and trees. Math. Syst. Theory, 15(1):225--249, 1981.
[24]
U. P. Khedker and D. M. Dhamdhere. A generalized theory of bit vector data flow analysis. ACM Trans. Program. Lang. Syst., 16(5): 1472--1511, 1994.
[25]
D. Knuth. Semantics of context-free languages: Correction. Math. Syst. Theory, 5(2):95--96, 1971.
[26]
D. E. Knuth. Semantics of context-free languages. Theory Comput. Syst., 2(2):127--145, 1968.
[27]
N. Kobayashi, K. Matsuda, A. Shinohara, and K. Yaguchi. Functional programs as compressed data. Higher-Order and Symbolic Computation, pages 1--46, 2013.
[28]
S. Lerner, D. Grove, and C. Chambers. Composing dataflow analyses and transformations. In POPL, pages 270--282, 2002.
[29]
J. R. Lewis, J. Launchbury, E. Meijer, and M. B. Shields. Implicit parameters: dynamic scoping with static types. In POPL, 2000.
[30]
M. Lohrey and S. Maneth. Tree automata and XPath on compressed trees. In CIAA, 2006.
[31]
A. Middelkoop. Inference with Attribute Grammars. PhD thesis, Universiteit Utrecht, Feb. 2012.
[32]
B. C. Oliveira and W. R. Cook. Functional programming with structured graphs. In ICFP, 2012.
[33]
B. C. d. S. Oliveira and A. Löh. Abstract syntax graphs for domain specific languages. In PEPM, 2013.
[34]
D. Quernheim and K. Knight. Dagger: A toolkit for automata on directed acyclic graphs. In FSMNLP, 2012.
[35]
J.-C. Raoult. Problem #70: Design a notion of automata for graphs, 2005. URL http://rtaloop.mancoosi.univ-paris-diderot.fr/problems/70.html. The RTA list of open problems.
[36]
T. Rompf and M. Odersky. Lightweight modular staging: A pragmatic approach to runtime code generation and compiled DSLs. In GPCE, 2010.
[37]
M. Rosendahl. Abstract interpretation using attribute grammars. In WAGA, 1990.
[38]
J. Saraiva, D. Swierstra, and M. Kuiper. Functional incremental attribute evaluation. In Compiler Construction, 2000.
[39]
M. Viera, S. D. Swierstra, and W. Swierstra. Attribute grammars fly first-class. In ICFP, 2009.
[40]
H. H. Vogt, S. D. Swierstra, and M. F. Kuiper. Higher order attribute grammars. In PLDI, 1989.
[41]
A. R. Yakushev, S. Holdermans, A. Löh, and J. Jeuring. Generic programming with fixed points for mutually recursive datatypes. In ICFP, 2009.

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
PEPM '15: Proceedings of the 2015 Workshop on Partial Evaluation and Program Manipulation
January 2015
152 pages
ISBN:9781450332972
DOI:10.1145/2678015
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

Sponsors

In-Cooperation

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 13 January 2015

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. attribute grammars
  2. graph traversal
  3. haskell
  4. sharing

Qualifiers

  • Research-article

Funding Sources

Conference

POPL '15
Sponsor:

Acceptance Rates

PEPM '15 Paper Acceptance Rate 14 of 27 submissions, 52%;
Overall Acceptance Rate 66 of 120 submissions, 55%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 151
    Total Downloads
  • Downloads (Last 12 months)4
  • Downloads (Last 6 weeks)0
Reflects downloads up to 02 Mar 2025

Other Metrics

Citations

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media