Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tonyg/3ba09a4185c87c7f0daf0de532950ed3 to your computer and use it in GitHub Desktop.
Save tonyg/3ba09a4185c87c7f0daf0de532950ed3 to your computer and use it in GitHub Desktop.
A couple of fantasy abstracts

Semi-automatic Defunctionalization of Continuations

Tony Garnock-Jones. February 2016.

Abstract

Programmers use continuations to achieve all manner of interesting control effects (e.g. Shivers & Turon 2011). But common representations of continuations cause problems in practice in two ways. On one hand, continuations represented as functions are entirely opaque; the only available operation is to invoke the continuation. On the other hand, continuations represented as reified machine stacks expose too much information; irrelevant detail of the program's information becomes visible. In this paper, we present a design for a middle-ground. Using our new language construct, continuations are represented as censored reified machine stacks. Programmers precisely control the information and behavior associated with each frame in the continuation, allowing them the benefits of automatic continuation reification combined with the benefits of a defunctionalized representation of control as data.


[1] "Modular rollback through control logging: a pair of twin functional pearls", Olin Shivers and Aaron Turon, ICFP 2011, http://dx.doi.org/10.1145/2034773.2034783

[2] M. Felleisen, M. Wand, D. P. Friedman, and B. F. Duba, “Abstract Continuations: A Mathematical Semantics for Handling Full Functional Jumps,” in ACM Conf. on LISP and Functional Programming, 1988, pp. 52–62.

[3] G. Pettyjohn, J. Clements, J. Marshall, S. Krishnamurthi, and M. Felleisen, “Continuations from generalized stack inspection,” ACM SIGPLAN Not., vol. 40, no. 9, p. 216, 2005.

Structured Reflection on Continuations is Possible, Interesting and Useful

Tony Garnock-Jones. September 2017

Abstract

Felleisen et al [1] showed that an abstract algebraic treatment of evaluation contexts was possible, interesting and useful. However, algebras capturing implementation-level control structure are unsuitable for reflective use, precisely because they capture an implementation- rather than a specification-level description of the evaluation context. We introduce a language for arbitrary specification-level algebras describing high-level perspectives on program tasks, and a mechanism for ensuring that implementation-level control context refines specification-level control context. We then allow programs to not only capture and reinstate but to analyse and synthesise these structures at runtime. Tuning of the specification algebra allows precise control over the level of detail exposed in reflective access, and has practical benefits for orthogonal persistence, for code upgrade, for network mobility, and for program execution visualisation and debugging, as well as offering the promise of new approaches to program verification.


[1] M. Felleisen, M. Wand, D. P. Friedman, and B. F. Duba, “Abstract Continuations: A Mathematical Semantics for Handling Full Functional Jumps,” in ACM Conf. on LISP and Functional Programming, 1988, pp. 52–62.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment