Staged Computation with Names and Necessity
journal contributionposted on 01.01.1981, 00:00 authored by Aleksandar Nanevski, Frank Pfenning
Staging is a programming technique for dividing the computation in order to exploit the early availability of some arguments. In the early stages the program uses the available arguments to generate, at run time, the code for the late stages. A type system for staging should ensure that only well-typed expressions are generated, and that only expressions with no free variables are permitted for evaluation. In this paper, we present a calculus for staged computation in which code from the late stages is composed by splicing smaller code fragments into a larger context, possibly incurring capture of free variables. The type system ensures safety by tracking the names of free variables for each code fragment. The type system is based on the necessity operator [square, open] from constructive modal logic, which we index with a set of names C. Our type [square, open]CA classifies expressions of type A that belong to the late stage, and whose free names are in the set C.