Common subexpressions are uncommon in lazy functional languages

  • Olaf Chitil
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 1467)


Common subexpression elimination is a well-known compiler optimisation that saves time by avoiding the repetition of the same computation. In lazy functional languages, referential transparency renders the identification of common subexpressions very simple. More common subexpressions can be recognised because they can be of arbitrary type whereas standard common subexpression elimination only shares primitive values. However, because lazy functional languages decouple program structure from data space allocation and control flow, analysing its effects and deciding under which conditions the elimination of a common subexpression is beneficial proves to be quite difficult. We developed and implemented the transformation for the language Haskell by extending the Glasgow Haskell compiler. On real-world programs the transformation showed nearly no effect. The reason is that common subexpressions whose elimination could speed up programs are uncommon in lazy functional languages.


Transformation Rule Cost Centre Repeated Computation Case Expression Safe Type 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. [1]
    A Aho, R Sethi, and J Ullman. Compilers: Principles, Techniques and Tools. Addison-Wesley, 1986.Google Scholar
  2. [2]
    Adrew W Appel. Compiling with Continuations. Cambridge University Press, 1992.Google Scholar
  3. [3]
    Olaf Chitil. Adding an optimisation pass to the Glasgow Haskell compiler. ttp://, November 1997.Google Scholar
  4. [4]
    The Glasgow Haskell compiler. ttp:// Scholar
  5. [5]
    Simon D Marlow. Deforestation for Higher-Order Functional Programs. PhD thesis, University of Glasgow, September 1995.Google Scholar
  6. [6]
    Christian Mossin, David N Turner, and Philip Wadler. Once upon a type. Technical Report TR-1995-8, University of Glasgow, 1995. Extended version of [?].Google Scholar
  7. [7]
    Will Partain. The Nofib benchmark suite of Haskell programs. In Functional Programming, Glasgow 1992, Workshops in Computing, pages 195–202. Springer-Verlag, 1992.Google Scholar
  8. [8]
    Will Partain. How to add an optimisation pass to the Glasgow Haskell compiler (two months before version 0.23). Part of the GHC 0.29 distribution, October 1994.Google Scholar
  9. [9]
    John Peterson, Kevin Hammond, et al. Report on the Programming Language Haskell, version 1.4. ttp://, 1997.Google Scholar
  10. [10]
    Simon L Peyton Jones. The Implementation of Functional Programming Languages. Prentice-Hall, 1987.Google Scholar
  11. [11]
    Simon L Peyton Jones. Implementing lazy functional languages on stock hardware: the Spinless Tagless G-machine. J. Functional Programming, 2(2): 127–202, 1992.CrossRefGoogle Scholar
  12. [12]
    Simon L Peyton Jones and John Launchbury. Unboxed values as first class citizens in a non-strict functional language. In Conf. on Functional Programming Languages and Computer Architecture, pages 636–666, 1991.Google Scholar
  13. [13]
    Simon L Peyton Jones and André L M Santos. A transformation-based optimiser for Haskell. Science of Computer Programming, 1997.Google Scholar
  14. [14]
    Patrick M Sansom and Simon L Peyton Jones. Time and space profiling for nonstrict, higher-order functional languages. In 22nd ACM Symposium on Principles of Programming Languages, January 1995.Google Scholar
  15. [15]
    André L M Santos. Compilation by transformation in non-strict functional languages. PhD thesis, University of Glasgow, July 1995.Google Scholar
  16. [16]
    D Tarditi, G Morrisett, P Cheng, C Stone, R Harper, and P Lee. TIL: A type-directed optimizing compiler for ML. In Sigplan Symposium on Programming Language Design and Implementation, 1996.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 1998

Authors and Affiliations

  • Olaf Chitil
    • 1
  1. 1.Lehrstuhl für Informatik IIAachen University of TechnologyGermany

Personalised recommendations