A monadic approach for avoiding code duplication when staging memoized functions

  • Authors:
  • Kedar Swadi;Walid Taha;Oleg Kiselyov;Emir Pasalic

  • Affiliations:
  • Presistent Systems Pvt. Ltd., Pune, India;Rice University, Houston, TX;FNMOC, Monterey, CA;Rice University, Houston, TX

  • Venue:
  • Proceedings of the 2006 ACM SIGPLAN symposium on Partial evaluation and semantics-based program manipulation
  • Year:
  • 2006

Quantified Score

Hi-index 0.02

Visualization

Abstract

Building program generators that do not duplicate generated code can be challenging. At the same time, code duplication can easily increase both generation time and runtime of generated programs by an exponential factor. We identify an instance of this problem that can arise when memoized functions are staged. Without addressing this problem, it would be impossible to effectively stage dynamic programming algorithms. Intuitively, direct staging undoes the effect of memoization. To solve this problem once and for all, and for any function that uses memoization, we propose a staged monadic combinator library. Experimental results confirm that the library works as expected. Preliminary results also indicate that the library is useful even when memoization is not used.