Abstract

Generic programming libraries such as Scrap Your Boilerplate eliminate the need to write repetitive code, but typically introduce significant performance overheads. This leaves programmers with the regrettable choice between writing succinct but slow programs and writing tedious but efficient programs. Applying structured multi-stage programming techniques transforms Scrap Your Boilerplate from an inefficient library into a typed optimising code generator, bringing its performance in line with hand-written code, and so combining high-level programming with uncompromised performance.

Highlights

  • The promise of generic programming is the elimination of the tedious boilerplate code used to traverse complex data structures

  • The central contribution of this work is the principled application of staging techniques to transform a generic programming library into a typed optimising code generator

  • Case lifting for binary sums is, found in the broader literature relating to normalization by evaluation and type-directed partial evaluation [Balat et al 2004; Lindley 2007]

Read more

Summary

INTRODUCTION

You might use a generic programming library such as Scrap Your Boilerplate [Lämmel and Peyton Jones 2003] (SYB), and write code like the following: listify evenp v. This snippet lists all even integers within v, whether v is a list, tree, pair, or some more complex structure. Here is the code generated by the staged listify when v has typeintstring listlist Ð that is, when v is an association list whose keys are integers and whose values are lists of strings: let rec f l = match l with | [] → [] | hd ȷȷ tl → letxy = hd in if evenp x x ȷȷ f tl else f tl. The listify code generator has determined that the value y can be ignored, since a string list cannot contain an int

Outline and Contributions
SYB Basics
The First SYB Ingredient
The Second SYB Ingredient
The Third SYB Ingredient
Staged Generic Operations
Staged Traversal Schemes
Performance of the Naive Staging
Partially-Static Data
Branch Pruning
Recursive Branch Elimination
EVALUATION
RELATED WORK
CONCLUSION
Full Text
Paper version not known

Talk to us

Join us for a 30 min session where you can share your feedback and ask us any queries you have

Schedule a call

Disclaimer: All third-party content on this website/platform is and will remain the property of their respective owners and is provided on "as is" basis without any warranties, express or implied. Use of third-party content does not indicate any affiliation, sponsorship with or endorsement by them. Any references to third-party content is to identify the corresponding services and shall be considered fair use under The CopyrightLaw.