Abstract
Generic functions are defined by induction on the structural representation of types. As a consequence, by defining just a single generic operation, one acquires this operation over any particular type. An instance on a specific type is generated by interpretation of the type’s structure. A direct translation leads to extremely inefficient code that involves many conversions between types and their structural representations. In this paper we present an optimization technique based on compile-time symbolic evaluation. We prove that the optimization removes the overhead of the generated code for a considerable class of generic functions. The proof uses typing to identify intermediate data structures that should be eliminated. In essence, the output after optimization is similar to hand-written code.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
van Arkel, D., van Groningen, J., Smetsers, S.: Fusion in practice. In: Peña, R., Arts, T. (eds.) IFL 2002. LNCS, vol. 2670, pp. 51–67. Springer, Heidelberg (2003) Departamento de Sistemas Informáticos y Programación, Universidad Complutense de Madrid, Springer (2003)
Aehlig, K., Joachimski, F.: Operational aspects of normalization by evaluation, Submitted to MSCS, Available from http://www.mathematik.uni-muenchen.de/~joachski (2001)
Alimarine, A., Plasmijer, R.: A generic programming extension for Clean. In: Arts, T., Mohnen, M. (eds.) Proceedings of the 13th International Workshop on Implementation of Functional Languages, IFL 2001, Stockholm, Sweden, September 2001, pp. 257–278 (2001) Ericsson Computer Science Laboratory
Alimarine, A., Smetsers, S.: Efficient generic functional programming. Technical report, Nijmegen Institute for Computing and Information Sciences, University of Nijmegen, The Netherlands (2003) (to appear)
Chin, W.-N.: Safe fusion of functional expressions II: further improvements. Journal of Functional Programming 4(4), 515–555 (1994)
Clarke, D., Hinze, R., Jeuring, J., Löh, A., de Wit, J.: The generic haskell user’s guide. Technical report, uu-cs-2002-047, Utrecht University (2002)
Chin, W.-N., Khoo, S.-C.: Better consumers for program specializations. Journal of Functional and Logic Programming 1996(4) (November 1996)
Danvy, O., Malmkjær, K., Palsberg, J.: Eta-expansion does the trick. ACM Transactions on Programming Languages and Systems 18(6), 730–751 (1996)
Filinski, A.: A semantic account of type-directed partial evaluation. In: Principles and Practice of Declarative Programming, pp. 378–395 (1999)
Hinze, R.: A generic programming extension for Haskell. In: Meijer, E. (ed.) Proceedings of the 3rd Haskell Workshop, Paris, France (September 1999) The proceedings appeared as a technical report of Universiteit Utrecht, UU-CS-1999-28
Hinze, R.: Generic programs and proofs. Habilitationsschrift, Universität Bonn (October 2000)
Hinze, R.: Polytypic values possess polykinded types. In: Backhouse, R., Oliveira, J.N. (eds.) MPC 2000. LNCS, vol. 1837, pp. 2–27. Springer, Heidelberg (2000)
Hinze, R., Jones, S.P.: Derivable type classes. In: Hutton, G. (ed.) Proceedings of the 2000 ACM SIGPLAN Haskell Workshop, August 2001. Electronic Notes in Theoretical Computer Science, vol. 41.1, Elsevier Science, Amsterdam (2001) The preliminary proceedings appeared as a University of Nottingham technical report
Jansson, P., Jeuring, J.: Polyp - a polytypic programming language extension. In: The 24th ACM Symposium on Principles of Programming Languages, POPL 1997, pp. 470–482. ACM Press, New York (1997)
Jørgensen, J.: Generating a compiler for a lazy language by partial evaluation, popl ’92. In: The 19th ACM Symposium on Principles of Programming Languages, Albuquerque, New Mexico, January 1992, pp. 258–268. ACM Press, New York (1992)
Leuschel, M.: Homeomorphic embedding for online termination. Technical Report DSSE-TR-98-11, Department of Electronics and Computer Science, University of Southampton, UK (October 1998)
Nielson, H.R., Nielson, F.: Semantics with Applications: A Formal Introduction. Wiley Professional Computing (1992) ISBN 0 471 92980 8
Pierce, B.C.: Types and Programming Languages. The MIT Press, Cambridge (2002) ISBN 0–262–16209–1
Sperber, M., Thiemann, P.: Realistic compilation by partial evaluation. In: Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language Design and Implementation, May 1996, pp. 206–214 (1996)
Takano, A., Meijer, E.: Shortcut deforestation in calculational form. In: Conf. Record 7th ACM SIGPLAN/SIGARCH Int. Conf. on Functional Programming Languages and Computer Architecture, FPCA 1995, La Jolla, San Diego, CA, June 1995, pp. 306–313. ACM Press, New York (1995)
Wadler, P.: Deforestation: transforming programs to eliminate trees. In: Ganzinger, H. (ed.) ESOP 1988. LNCS, vol. 300, pp. 344–358. Springer, Heidelberg (1988)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2004 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Alimarine, A., Smetsers, S. (2004). Optimizing Generic Functions. In: Kozen, D. (eds) Mathematics of Program Construction. MPC 2004. Lecture Notes in Computer Science, vol 3125. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-540-27764-4_3
Download citation
DOI: https://doi.org/10.1007/978-3-540-27764-4_3
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-22380-1
Online ISBN: 978-3-540-27764-4
eBook Packages: Springer Book Archive