Skip to main content

A Generic Functional Representation of Sorted Trees Supporting Attribution

(Haskell Can Do It)

  • Chapter
Programming Logics

Part of the book series: Lecture Notes in Computer Science ((LNTCS,volume 7797))

Abstract

Many important tasks and algorithms in computer science build on sorted trees. Typical examples are the translation of programs represented by syntax trees or the processing of (recursive) data structures following some XML schema. In purely functional programming, sorted trees are usually implemented by terms of recursive data types such that a term represents a tree node and the subterms represent its children. The drawback of this representation is that the context of a tree node is not accessible and has to be managed by different means, e.g., by additional arguments of the functions working on the tree.

In this paper, we present a pattern for the realization of sorted trees that overcomes this drawback. The technique is fully declarative. In contrast to competing patterns for trees such as Zippers, it supports pattern matching on the tree data structure. Functions on tree nodes can be used to express the decoration of trees by attribute values in a flexible way. In particular, links between tree nodes can easily be defined and attributions can be modularized into phases with clear interfaces. Techniques adapted from the “Scrap your boilerplate” approach allow for the high-level specification of contextual constraints. We show how our approach can be realized in Haskell and discuss tool support.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. Augusteijn, L.: The Elegant Compiler Generator System. In: Deransart, P., Jourdan, M. (eds.) Attribute Grammars and their Applications. LNCS, vol. 461, pp. 238–254. Springer, Heidelberg (1990)

    Chapter  Google Scholar 

  2. Deransart, P., Jourdan, M., Lorho, B. (eds.): Attribute Grammars. LNCS, vol. 323. Springer, Heidelberg (1988)

    MATH  Google Scholar 

  3. Ganzinger, H.: Increasing modularity and language-independency in automatically generated compilers. Science of Computer Programming (1983)

    Google Scholar 

  4. Ganzinger, H., Giegerich, R.: Attribute coupled grammars. In: SIGPLAN 1984 Symposium on Compiler Construction, SIGPLAN Notices, vol. 19(6), pp. 157–170. ACM Press (1984)

    Google Scholar 

  5. Ganzinger, H., Giegerich, R., Möncke, U., Wilhelm, R.: A truly generative semantics-directed compiler generator. In: SIGPLAN 1982: Proceedings of the 1982 SIGPLAN Symposium on Compiler Construction, pp. 172–184. ACM Press (1982)

    Google Scholar 

  6. Hedin, G.: An Overview of Door Attribute Grammars. In: Fritzson, P.A. (ed.) CC 1994. LNCS, vol. 786, pp. 31–51. Springer, Heidelberg (1994)

    Chapter  Google Scholar 

  7. Hendriks, P.R.H.: ASF system user’s guide. Technical Report CS-R8823, CWI (1988)

    Google Scholar 

  8. Hinze, R.: Memo functions, polytypically! In: Proceedings of the 2nd Workshop on Generic Programming, pp. 17–32 (2000)

    Google Scholar 

  9. Hinze, R., Jeuring, J.: Weaving a web. J. Funct. Program. 11(6), 681–689 (2001)

    Article  MathSciNet  MATH  Google Scholar 

  10. Huet, G.: The Zipper. Journal of Functional Programming 7(5), 549–554 (1997)

    Article  MathSciNet  MATH  Google Scholar 

  11. Johnson, T.: Attribute Grammars as a Functional Programming Paradigm. In: Kahn, G. (ed.) FPCA 1987. LNCS, vol. 274, pp. 154–173. Springer, Heidelberg (1987)

    Chapter  Google Scholar 

  12. Jourdan, M., Parigot, D.: The FNC-2 system: Advances in attribute grammars technology. Technical Report No. 834, INRIA (April 1988)

    Google Scholar 

  13. Kastens, U.: Attributed Grammars as a Specification Method. In: Alblas, H., Melichar, B. (eds.) SAGA School 1991. LNCS, vol. 545, pp. 16–47. Springer, Heidelberg (1991)

    Chapter  Google Scholar 

  14. Kastens, U., Hutt, B., Zimmermann, E. (eds.): GAG: A Practical Compiler Generator. LNCS, vol. 141. Springer, Heidelberg (1982)

    MATH  Google Scholar 

  15. Knuth, D.E.: The semantics of context-free languages. Mathematical Systems Theory (1968)

    Google Scholar 

  16. Lämmel, R.: Scrap your boilerplate with XPath-like combinators. In: POPL 2007, Proceedings. ACM Press (January 2007)

    Google Scholar 

  17. Lämmel, R., Peyton Jones, S.: Scrap your boilerplate: a practical design pattern for generic programming. In: ACM SIGPLAN Notices, Proceedings of the ACM SIGPLAN Workshop on Types in Language Design and Implementation TLDI, vol. 38(3), pp. 26–37 (2003)

    Google Scholar 

  18. Lämmel, R., Peyton Jones, S.: Scrap more boilerplate: reflection, zips, and generalised casts. In: Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP 2004), pp. 244–255. ACM Press (2004)

    Google Scholar 

  19. Michel, P.: Adding position structures to Katja. Technical Report 353/06, University of Kaiserslautern (June 2005)

    Google Scholar 

  20. Peyton Jones, S., Marlow, S., Elliott, C.: Stretching the Storage Manager: Weak Pointers and Stable Names in Haskell. In: Koopman, P., Clack, C. (eds.) IFL 1999. LNCS, vol. 1868, pp. 37–58. Springer, Heidelberg (2000)

    Chapter  Google Scholar 

  21. Poetzsch-Heffter, A.: Prototyping realistic programming languages based on formal specifications. Acta Informatica 34, 737–772 (1997)

    Article  MathSciNet  MATH  Google Scholar 

  22. Poetzsch-Heffter, A., Rauch, N.: Application and Formal Specification of Sorted Term-Position Algebras. In: Fiadeiro, J.L., Mosses, P.D., Yu, Y. (eds.) WADT 2004. LNCS, vol. 3423, pp. 201–217. Springer, Heidelberg (2005)

    Chapter  Google Scholar 

  23. Reps, T., Marceau, C., Teitelbaum, T.: Remote attribute updating for language-based editors. In: ACM-SIGPLAN ACM-SIGACT (ed.) Thirteenth Annual ACM Symposium on Principles of Programming Languages, pp. 1–13. ACM Press (January 1986)

    Google Scholar 

  24. Viera, M., Swierstra, S.D., Swierstra, W.: Attribute grammars fly first-class: how to do aspect oriented programming in haskell. In: Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming, ICFP 2009, pp. 245–256. ACM, New York (2009)

    Google Scholar 

  25. Vogt, H., Swierstra, S., Kuiper, M.: Higher order attribute grammars. In: SIGPLAN 1989 Conference on Progamming Language Design and Implementation, SIGPLAN Notices, vol. 24(7), pp. 131–145. ACM Press (1989)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2013 Springer-Verlag Berlin Heidelberg

About this chapter

Cite this chapter

Gaillourdet, JM., Michel, P., Poetzsch-Heffter, A., Rauch, N. (2013). A Generic Functional Representation of Sorted Trees Supporting Attribution. In: Voronkov, A., Weidenbach, C. (eds) Programming Logics. Lecture Notes in Computer Science, vol 7797. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-37651-1_4

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-37651-1_4

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-37650-4

  • Online ISBN: 978-3-642-37651-1

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics