Skip to main content

Optimizing Generic Functions

  • Conference paper
Mathematics of Program Construction (MPC 2004)

Part of the book series: Lecture Notes in Computer Science ((LNCS,volume 3125))

Included in the following conference series:

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.

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

Access this chapter

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

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.

Similar content being viewed by others

References

  1. 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)

    Google Scholar 

  2. Aehlig, K., Joachimski, F.: Operational aspects of normalization by evaluation, Submitted to MSCS, Available from http://www.mathematik.uni-muenchen.de/~joachski (2001)

  3. 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

    Google Scholar 

  4. 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)

    Google Scholar 

  5. Chin, W.-N.: Safe fusion of functional expressions II: further improvements. Journal of Functional Programming 4(4), 515–555 (1994)

    Article  Google Scholar 

  6. 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)

    Google Scholar 

  7. Chin, W.-N., Khoo, S.-C.: Better consumers for program specializations. Journal of Functional and Logic Programming 1996(4) (November 1996)

    Google Scholar 

  8. Danvy, O., Malmkjær, K., Palsberg, J.: Eta-expansion does the trick. ACM Transactions on Programming Languages and Systems 18(6), 730–751 (1996)

    Article  Google Scholar 

  9. Filinski, A.: A semantic account of type-directed partial evaluation. In: Principles and Practice of Declarative Programming, pp. 378–395 (1999)

    Google Scholar 

  10. 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

    Google Scholar 

  11. Hinze, R.: Generic programs and proofs. Habilitationsschrift, Universität Bonn (October 2000)

    Google Scholar 

  12. 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)

    Chapter  Google Scholar 

  13. 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

    Google Scholar 

  14. 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)

    Chapter  Google Scholar 

  15. 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)

    Chapter  Google Scholar 

  16. 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)

    Google Scholar 

  17. Nielson, H.R., Nielson, F.: Semantics with Applications: A Formal Introduction. Wiley Professional Computing (1992) ISBN 0 471 92980 8

    Google Scholar 

  18. Pierce, B.C.: Types and Programming Languages. The MIT Press, Cambridge (2002) ISBN 0–262–16209–1

    Google Scholar 

  19. 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)

    Google Scholar 

  20. 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)

    Google Scholar 

  21. Wadler, P.: Deforestation: transforming programs to eliminate trees. In: Ganzinger, H. (ed.) ESOP 1988. LNCS, vol. 300, pp. 344–358. Springer, Heidelberg (1988)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Editor information

Editors and Affiliations

Rights and permissions

Reprints 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

Publish with us

Policies and ethics