Skip to main content
Log in

A functional approach to generic programming using adaptive traversals

  • Published:
Higher-Order and Symbolic Computation

Abstract

Writing functions over complex user-defined datatypes can be tedious and error prone. Generic (or polytypic) programming and higher order functions like foldr have resolved some of these issues, but can be too general to be practically useful for larger collections of data types. In this paper we present a traversal-based approach to generic programming using function sets. Our traversal is an adaptive, higher-order function that employs an asymmetric type-based multiple dispatch to fold over arbitrarily complex structures. We introduce our approach in the context of our Scheme library implementation, present a typed model of our system, and provide a proof of type soundness, showing that our flexible, adaptive approach is both useful and safe.

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

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. Agrawal, R., Demichiel, L.G., Lindsay, B.G.: Static type checking of multi-methods. In: OOPSLA ’91, pp. 113–128. ACM, New York (1991)

    Chapter  Google Scholar 

  2. Backhouse, R., Jansson, P., Jeuring, J., Meertens, L.: Generic programming—an introduction. In: Swierstra, S., Oliveira, J., Henriques, P. (eds.) Advanced Functional Programming. LNCS, vol. 1608, pp. 28–115. Springer, Berlin (1999)

    Chapter  Google Scholar 

  3. Bochmann, G.V.: Semantic evaluation from left to right. Commun. ACM 19(2), 55–62 (1976)

    Article  MathSciNet  MATH  Google Scholar 

  4. Chadwick, B.: Algorithms in DemeterF (May 2009). http://www.ccs.neu.edu/home/chadwick/files/algo.pdf

  5. Chadwick, B., Lieberherr, K.: A type system for functional traversal-based aspects. In: AOSD 2009, FOAL Workshop. ACM, New York (2009)

    Google Scholar 

  6. Chadwick, B., Lieberherr, K.J.: Weaving generic programming and traversal performance. In: Jézéquel, J.-M., Südholt, M. (eds.) AOSD ’10, pp. 61–72. ACM, New York (2010)

    Google Scholar 

  7. Chambers, C., Leavens, G.T.: Typechecking and modules for multimethods. ACM Trans. Program. Lang. Syst. 17(6), 805–843 (1995)

    Article  Google Scholar 

  8. Oliveira, B.C.d.S., Wang, M., Gibbons, J.: The visitor pattern as a reusable, generic, type-safe component. In: Kiczales, G. (ed.) OOPSLA ’08, October (2008)

    Google Scholar 

  9. Danvy, O.: From reduction-based to reduction-free normalization. In: Koopman, P., Plasmeijer, R., Swierstra, D. (eds.) Advanced Functional Programming, Sixth International School, Nijmegen, The Netherlands, May. LNCS, vol. 5382, pp. 66–164. Springer, Berlin (2008)

    Google Scholar 

  10. Danvy, O., Millikin, K.: On the equivalence between small-step and big-step abstract machines: a simple application of lightweight fusion. Inf. Process. Lett. 106(3), 100–109 (2008)

    Article  MathSciNet  MATH  Google Scholar 

  11. Danvy, O., Schultz, U.P.: Lambda-dropping: transforming recursive equations into programs with block structure. Theor. Comput. Sci. 248(1–2), 243–287 (2000)

    Article  MATH  Google Scholar 

  12. Engelfriet, J., Filé, G.: Passes, sweeps, and visits in attribute grammars. J. ACM 36(4), 841–869 (1989)

    Article  MATH  Google Scholar 

  13. Gibbons, J.: Datatype-generic programming. In: Backhouse, R., Gibbons, J., Hinze, R., Jeuring, J. (eds.) Spring School on Datatype-Generic Programming. LNCS, vol. 4719. Springer, Berlin (2007)

    Google Scholar 

  14. Hinze, R.: A new approach to generic functional programming. In: POPL ’99, pp. 119–132. ACM, New York (1999)

    Google Scholar 

  15. Jansson, P., Jeuring, J.: PolyP—a polytypic programming language extension. In: POPL’97, pp. 470–482. ACM, New York (1997)

    Google Scholar 

  16. Jones, S.P.: Haskell 98 Language and Libraries: The Revised Report. Cambridge University Press, Cambridge (2003)

    Google Scholar 

  17. Kelsey, R., Clinger, W., Rees, J. (eds.): Revised5 report on the algorithmic language Scheme. Higher-Order Symb. Comput. 11(1), 7–105 (1998)

  18. Knuth, D.E.: Semantics of context-free languages. Theory Comput. Syst. 2(2), 127–145 (1968)

    MathSciNet  MATH  Google Scholar 

  19. Krishnamurthi, S., Felleisen, M., Friedman, D.P.: Synthesizing object-oriented and functional design to promote re-use. In: ECOOP ’98, pp. 91–113. Springer, London (1998)

    Google Scholar 

  20. Lämmel, R., Visser, J.: Typed combinators for generic traversal. In: PADL ’02. LNCS, vol. 2257, pp. 137–154. Springer, Berlin (2002)

    Google Scholar 

  21. Lämmel, R., Peyton Jones, S.: Scrap your boilerplate: a practical design pattern for generic programming. In: TLDI ’03, pp. 26–37. ACM, New York (2003)

    Chapter  Google Scholar 

  22. Lämmel, R., Peyton Jones, S.: Scrap more boilerplate: reflection, zips, and generalised casts. In: ICFP ’04, pp. 244–255. ACM, New York (2004)

    Chapter  Google Scholar 

  23. Lämmel, R., Peyton Jones, S.: Scrap your boilerplate with class: extensible generic functions. In: ICFP ’05, pp. 204–215. ACM, New York (2005)

    Chapter  Google Scholar 

  24. Lämmel, R., Visser, J., Kort, J.: Dealing with large bananas. In: Jeuring, J. (ed.) WGP ’00, July, pp. 46–59 (2000)

    Google Scholar 

  25. Lieberherr, K.J.: Adaptive Object-Oriented Software: The Demeter Method with Propagation Patterns. PWS Publishing Company, Boston (1996)

    Google Scholar 

  26. Loeh, A., Jeuring, J. (eds.): Dave Clarke, Ralf Hinze, Alexey Rodriguez, and Jan de Wit. Generic haskell user’s guide—version 1.42 (coral). Technical Report UU-CS-2005-004, Department of Information and Computing Sciences, Utrecht University (2005)

  27. Meijer, E., Fokkinga, M., Paterson, R.: Functional programming with bananas, lenses, envelopes and barbed wire. In: Hughes, J. (ed.) FPCA ’91, vol. 523, pp. 124–144. Springer, Berlin (1991)

    Google Scholar 

  28. Millstein, T.D., Chambers, C.: Modular statically typed multimethods. In: ECOOP ’99, pp. 279–303. Springer, London (1999)

    Google Scholar 

  29. Oliveira, B.C.: Modular visitor components. In: ECOOP ’09, pp. 269–293. Springer, Berlin (2009)

    Google Scholar 

  30. PLT Scheme. Website (2009). http://www.plt-scheme.org/

  31. Sheard, T., Fegaras, L.: A fold for all seasons. In: FPCA ’93, pp. 233–242. ACM, New York (1993)

    Chapter  Google Scholar 

  32. Steele, G.L. Jr.: Common LISP: The Language, 2nd edn. Digital Press, Newton (1990)

    MATH  Google Scholar 

  33. Stump, Aaron: Directly reflective meta-programming. High.-Order Symb. Comput. 22(2), 115–144 (2009)

    Article  Google Scholar 

  34. VanDrunen, T., Palsberg, J.: Visitor-oriented programming. In: FOOL ’04, January (2004)

    Google Scholar 

  35. Visser, J.: Visitor combination and traversal control. In: OOPSLA ’01, pp. 270–282. ACM, New York (2001)

    Chapter  Google Scholar 

  36. Wand, M., Kiczales, G., Dutchyn, C.: A semantics for advice and dynamic join points in aspect-oriented programming. ACM Trans. Program. Lang. Syst. 26(5), 890–910 (2004)

    Article  Google Scholar 

  37. Wright, A.K., Felleisen, M.: A syntactic approach to type soundness. Inf. Comput. 115, 38–94 (1994)

    Article  MathSciNet  MATH  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Bryan Chadwick.

Rights and permissions

Reprints and permissions

About this article

Cite this article

Chadwick, B., Lieberherr, K. A functional approach to generic programming using adaptive traversals. Higher-Order Symb Comput 23, 433–463 (2010). https://doi.org/10.1007/s10990-011-9064-1

Download citation

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10990-011-9064-1

Keywords

Navigation