Skip to main content
×
Home
    • Aa
    • Aa

Shifting the stage: Staging with delimited control

  • YUKIYOSHI KAMEYAMA (a1), OLEG KISELYOV (a2) and CHUNG-CHIEH SHAN (a3)
Abstract
Abstract

It is often hard to write programs that are efficient yet reusable. For example, an efficient implementation of Gaussian elimination should be specialized to the structure and known static properties of the input matrix. The most profitable optimizations, such as choosing the best pivoting or memoization, cannot be expected of even an advanced compiler because they are specific to the domain, but expressing these optimizations directly makes for ungainly source code. Instead, a promising and popular way to reconcile efficiency with reusability is for a domain expert to write code generators.

Two pillars of this approach are types and effects. Typed multilevel languages such as MetaOCaml ensure safety and early error reporting: a well-typed code generator neither goes wrong nor generates code that goes wrong. Side effects such as state and control ease correctness and expressivity: An effectful generator can resemble the textbook presentation of an algorithm, as is familiar to domain experts, yet insert let for memoization and if for bounds checking, as is necessary for efficiency. Together, types and effects enable structuring code generators as compositions of modules with well-defined interfaces, and hence scaling to large programs. However, blindly adding effects renders multilevel types unsound.

We introduce the first multilevel calculus with control effects and a sound type system. We give small-step operational semantics as well as a one-pass continuation-passing-style translation. For soundness, our calculus restricts the code generator's effects to the scope of generated binders. Even with this restriction, we can finally write efficient code generators for dynamic programming and numerical methods in direct style, like in algorithm textbooks, rather than in continuation-passing or monadic style.

Copyright
Linked references
Hide All

This list contains references from the content that can be linked to their source. For a full set of references and notes please see the PDF or HTML where available.

K. Asai (2009) On typing delimited continuations: Three new solutions to the printf problem. Higher-Order Symb. Comput. 22 (3), 275291.

A. Bondorf & O. Danvy (1991) Automatic autoprojection of recursive equations with global variables and abstract data types. Sci. Comput. Program. 16 (2), 151195.

J. Carette (2006) Gaussian Elimination: A case study in efficient genericity with MetaOCaml. Sci. Comput. Program. 62 (1), 324 (special issue on the First MetaOCaml Workshop 2004).

J. Carette & O. Kiselyov (2011) Multi-stage programming with functors and monads: Eliminating abstraction overhead from generic code. Sci. Comput. Program. 76 (5), 349375.

A. Cohen , S. Donadio , M. J. Garzarán , C. A. Herrmann , O. Kiselyov & D. A. Padua (2006) In search of a program generator to implement generic transformations for high-performance computing. Sci. Comput. Program. 62 (1), 2546.

O. Danvy (1998) Functional unparsing. J. Funct. Program. 8 (6), 621625.


R. Davies & F. Pfenning (2001) A modal analysis of staged computation. J. ACM 48 (3), 555604.

M. Felleisen (1991) On the expressive power of programming languages. Sci. Comput. Program. 17 (1–3), 3575.


M. Frigo & S. G. Johnson (2005) The design and implementation of FFTW3. Proc. IEEE 93 (2), 216231.


Y. Kameyama , O. Kiselyov & C.-c. Shan (2008) Closing the stage: From staged code to typed closures. In Proceedings of PEPM, San Francisco, CA, USA, pp. 147157.

M. Leone & P. Lee (1998) Dynamic specialization in the Fabius system. ACM Comput. Surv, 30(3es), article 23:123:6.

X. Leroy & F. Pessaux (2000) Type-based analysis of uncaught exceptions. ACM Tran. Prog. Lang. Syst. 22 (2), 340377.

D. Michie (1968) “Memo” functions and machine learning. Nature 218: 1922.

L. Moreau (1998) A syntactic theory of dynamic binding. Higher-Order Symb. Comput. 11 (3), 233279.

M. Püschel , J. M. F. Moura , J. Johnson , D. Padua , M. Veloso , B. W. Singer , J. Xiong , F. Franchetti , A. Gačić , Y. Voronenko , K. Chen , R. W. Johnson & N. Rizzolo (2005) SPIRAL: Code generation for DSP transforms. Proc. IEEE 93 (2), 232275.

E. Sumii and N. Kobayashi (2001) A hybrid approach to online and offline partial evaluation. Higher-Order Symb. Comput. 14 (2–3), 101142.


P. Thiemann (1999) Combinators for program generation. J. Funct. Program. 9 (5), 483525.

M. Tofte , L. Birkedal , M. Elsman & N. Hallenberg (2004) A retrospective on region-based memory management. Higher-Order Symb. Comput. 17 (3), 245265.


R. C. Whaley & A. Petitet (2005) Minimizing development and maintenance costs in supporting persistently optimized BLAS. Softw. Pract. Exp. 35 (2), 101121.

Recommend this journal

Email your librarian or administrator to recommend adding this journal to your organisation's collection.

Journal of Functional Programming
  • ISSN: 0956-7968
  • EISSN: 1469-7653
  • URL: /core/journals/journal-of-functional-programming
Please enter your name
Please enter a valid email address
Who would you like to send this to? *
×
Type Description Title
UNKNOWN
Supplementary Materials

Kameyama Supplementary Material
Kameyama Supplementary Material

 Unknown (61 KB)
61 KB