ABSTRACT
While many programmers appreciate the benefits of lazy programming at an abstract level, determining which parts of a concrete program to evaluate lazily poses a significant challenge for most of them. Over the past thirty years, experts have published numerous papers on the problem, but developing this level of expertise requires a significant amount of experience.
We present a profiling-based technique that captures and automates this expertise for the insertion of laziness annotations into strict programs. To make this idea precise, we show how to equip a formal semantics with a metric that measures waste in an evaluation. Then we explain how to implement this metric as a dynamic profiling tool that suggests where to insert laziness into a program. Finally, we present evidence that our profiler's suggestions either match or improve on an expert's use of laziness in a range of real-world applications.
Supplemental Material
- H. Abelson, G. J. Sussman, and J. Sussman. Structure and Interpretation of Computer Programs. MIT Press, 1984. Google ScholarDigital Library
- C. Barski. Land of Lisp. No Starch Press, 2011.Google Scholar
- S. Chang. Laziness by need. In Proc. 22nd ESOP, pages 81--100, 2013. Google ScholarDigital Library
- C. Clack and S. L. Peyton Jones. Strictness analysis -- a practical approach. In Proc. 2nd FPCA, pages 35--49, 1985. Google ScholarDigital Library
- R. Ennals and S. Peyton Jones. Optimistic evaluation: an adaptive evaluation strategy for non-strict programs. In Proc. 8th ICFP, pages 287--298, 2003. Google ScholarDigital Library
- K.-F. Faxén. Cheap eagerness: speculative evaluation in a lazy functional language. In Proc. 5th ICFP, pages 150--161, 2000. Google ScholarDigital Library
- M. Felleisen, R. B. Findler, and M. Flatt. Semantics Engineering with PLT Redex. MIT Press, 2009. Google ScholarDigital Library
- R. B. Findler, S. Guo, and A. Rogers. Lazy contract checking for immutable data structures. In Proc. 19th IFL, pages 111--128, 2007. Google ScholarDigital Library
- M. Flatt and PLT. Reference: Racket. Technical Report PLT-TR-2013-1, PLT Inc., 2013. http://racket-lang.org/tr1/.Google Scholar
- R. Hinze and R. Paterson. Finger trees: a simple general-purpose data structure. In J. Funct. Program., pages 197--217, 2006. Google ScholarDigital Library
- P. Hudak, J. Hughes, S. P. Jones, and P. Wadler. A history of Haskell: being lazy with class. In Proc. 3rd HOPL, pages 12--1--12--55, 2007. Google ScholarDigital Library
- J. Hughes. Why functional programming matters. Comp. J., 32:98--107, 1989. Google ScholarDigital Library
- D. Leijen and E. Meijer. Parsec: direct style monadic parser combinators for the real world. TR UU-CS-2001-35, Utrecht University, 2001.Google Scholar
- J.-W. Maessen. Eager Haskell: resource-bounded execution yields efficient iteration. In Proc. Haskell Workshop, pages 38--50, 2002. Google ScholarDigital Library
- F. Morandat, B. Hill, L. Osvald, and J. Vitek. Evaluating the design of the R language. In Proc. 26th ECOOP, pages 104--131, 2012. Google ScholarDigital Library
- A. Mycroft. Abstract interpretation and optimising transformations for applicative programs. PhD thesis, University of Edinburgh, 1981.Google Scholar
- C. Okasaki. Purely Functional Data Structures. Cambridge University Press, 1998. Google ScholarDigital Library
- B. O'Sullivan, D. Stewart, and J. Goerzen. Real World Haskell. O'Reilly Media, 2008. Google ScholarDigital Library
- G. D. Plotkin. Call-by-name, call-by-value and the λ-calculus. Theor. Comput. Sci., 1:125--159, 1975.Google ScholarCross Ref
- K. E. Schauser and S. C. Goldstein. How much non-strictness do lenient programs require? In Proc. 7th FPCA, pages 216--225, 1995. Google ScholarDigital Library
- P. Wadler. How to replace failure by a list of successes. In Proc. 2nd FPCA, pages 113--128, 1985. Google ScholarDigital Library
- G. Xu, N. Mitchell, M. Arnold, A. Rountev, E. Schonberg, and G. Sevitsky. Finding low-utility data structures. In Proc. 31st PLDI, pages 174--186, 2010. Google ScholarDigital Library
Index Terms
- Profiling for laziness
Recommendations
The interaction of contracts and laziness
PEPM '12: Proceedings of the ACM SIGPLAN 2012 workshop on Partial evaluation and program manipulationContract monitoring for strict higher-order functional languages has an intuitive meaning, an established theoretical basis, and a standard implementation. For lazy functional languages, the situation is less clear-cut. There is no agreed-upon intended ...
Profiling for laziness
POPL '14While many programmers appreciate the benefits of lazy programming at an abstract level, determining which parts of a concrete program to evaluate lazily poses a significant challenge for most of them. Over the past thirty years, experts have published ...
Complete Laziness: a Natural Semantics
Lazy evaluation (or call-by-need) is widely used and well understood, partly thanks to a clear operational semantics given by Launchbury. However, modern non-strict functional languages do not use plain call-by-need evaluation: they also use ...
Comments