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.
Similar content being viewed by others
References
Agrawal, R., Demichiel, L.G., Lindsay, B.G.: Static type checking of multi-methods. In: OOPSLA ’91, pp. 113–128. ACM, New York (1991)
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)
Bochmann, G.V.: Semantic evaluation from left to right. Commun. ACM 19(2), 55–62 (1976)
Chadwick, B.: Algorithms in DemeterF (May 2009). http://www.ccs.neu.edu/home/chadwick/files/algo.pdf
Chadwick, B., Lieberherr, K.: A type system for functional traversal-based aspects. In: AOSD 2009, FOAL Workshop. ACM, New York (2009)
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)
Chambers, C., Leavens, G.T.: Typechecking and modules for multimethods. ACM Trans. Program. Lang. Syst. 17(6), 805–843 (1995)
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)
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)
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)
Danvy, O., Schultz, U.P.: Lambda-dropping: transforming recursive equations into programs with block structure. Theor. Comput. Sci. 248(1–2), 243–287 (2000)
Engelfriet, J., Filé, G.: Passes, sweeps, and visits in attribute grammars. J. ACM 36(4), 841–869 (1989)
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)
Hinze, R.: A new approach to generic functional programming. In: POPL ’99, pp. 119–132. ACM, New York (1999)
Jansson, P., Jeuring, J.: PolyP—a polytypic programming language extension. In: POPL’97, pp. 470–482. ACM, New York (1997)
Jones, S.P.: Haskell 98 Language and Libraries: The Revised Report. Cambridge University Press, Cambridge (2003)
Kelsey, R., Clinger, W., Rees, J. (eds.): Revised5 report on the algorithmic language Scheme. Higher-Order Symb. Comput. 11(1), 7–105 (1998)
Knuth, D.E.: Semantics of context-free languages. Theory Comput. Syst. 2(2), 127–145 (1968)
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)
Lämmel, R., Visser, J.: Typed combinators for generic traversal. In: PADL ’02. LNCS, vol. 2257, pp. 137–154. Springer, Berlin (2002)
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)
Lämmel, R., Peyton Jones, S.: Scrap more boilerplate: reflection, zips, and generalised casts. In: ICFP ’04, pp. 244–255. ACM, New York (2004)
Lämmel, R., Peyton Jones, S.: Scrap your boilerplate with class: extensible generic functions. In: ICFP ’05, pp. 204–215. ACM, New York (2005)
Lämmel, R., Visser, J., Kort, J.: Dealing with large bananas. In: Jeuring, J. (ed.) WGP ’00, July, pp. 46–59 (2000)
Lieberherr, K.J.: Adaptive Object-Oriented Software: The Demeter Method with Propagation Patterns. PWS Publishing Company, Boston (1996)
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)
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)
Millstein, T.D., Chambers, C.: Modular statically typed multimethods. In: ECOOP ’99, pp. 279–303. Springer, London (1999)
Oliveira, B.C.: Modular visitor components. In: ECOOP ’09, pp. 269–293. Springer, Berlin (2009)
PLT Scheme. Website (2009). http://www.plt-scheme.org/
Sheard, T., Fegaras, L.: A fold for all seasons. In: FPCA ’93, pp. 233–242. ACM, New York (1993)
Steele, G.L. Jr.: Common LISP: The Language, 2nd edn. Digital Press, Newton (1990)
Stump, Aaron: Directly reflective meta-programming. High.-Order Symb. Comput. 22(2), 115–144 (2009)
VanDrunen, T., Palsberg, J.: Visitor-oriented programming. In: FOOL ’04, January (2004)
Visser, J.: Visitor combination and traversal control. In: OOPSLA ’01, pp. 270–282. ACM, New York (2001)
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)
Wright, A.K., Felleisen, M.: A syntactic approach to type soundness. Inf. Comput. 115, 38–94 (1994)
Author information
Authors and Affiliations
Corresponding author
Rights 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
Published:
Issue Date:
DOI: https://doi.org/10.1007/s10990-011-9064-1