Hostname: page-component-6766d58669-6mz5d Total loading time: 0 Render date: 2026-05-14T18:58:57.900Z Has data issue: false hasContentIssue false

Shifting the stage

Staging with delimited control

Published online by Cambridge University Press:  23 November 2011

YUKIYOSHI KAMEYAMA
Affiliation:
Department of Computer Science, University of Tsukuba (e-mail: kameyama@acm.org)
OLEG KISELYOV
Affiliation:
Monterey, CA, USA (e-mail: oleg@okmij.org)
CHUNG-CHIEH SHAN
Affiliation:
Cornell University (e-mail: ccshan@post.harvard.edu)
Rights & Permissions [Opens in a new window]

Abstract

Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the 'Save PDF' action button.

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.

Information

Type
Articles
Copyright
Copyright © Cambridge University Press 2011
Supplementary material: File

Kameyama Supplementary Material

Kameyama Supplementary Material

Download Kameyama Supplementary Material(File)
File 60.5 KB
Submit a response

Discussions

No Discussions have been published for this article.