15 research outputs found
From Reduction-Based to Reduction-Free Normalization
We present a systematic construction of a reduction-free normalization function. Starting from a reduction-based normalization function, i.e., the transitive closure of a one-step reduction function, we successively subject it to refocusing (i.e., deforestation of the intermediate reduced terms), simplification (i.e., fusing auxiliary functions), refunctionalization (i.e., Church encoding), and direct-style transformation (i.e., the converse of the CPS transformation). We consider two simple examples and treat them in detail: for the first one, arithmetic expressions, we construct an evaluation function; for the second one, terms in the free monoid, we construct an accumulator-based flatten function. The resulting two functions are traditional reduction-free normalization functions. The construction builds on previous work on refocusing and on a functional correspondence between evaluators and abstract machines. It is also reversible
A Strong Distillery
Abstract machines for the strong evaluation of lambda-terms (that is, under
abstractions) are a mostly neglected topic, despite their use in the
implementation of proof assistants and higher-order logic programming
languages. This paper introduces a machine for the simplest form of strong
evaluation, leftmost-outermost (call-by-name) evaluation to normal form,
proving it correct, complete, and bounding its overhead. Such a machine, deemed
Strong Milner Abstract Machine, is a variant of the KAM computing normal forms
and using just one global environment. Its properties are studied via a special
form of decoding, called a distillation, into the Linear Substitution Calculus,
neatly reformulating the machine as a standard micro-step strategy for explicit
substitutions, namely linear leftmost-outermost reduction, i.e., the extension
to normal form of linear head reduction. Additionally, the overhead of the
machine is shown to be linear both in the number of steps and in the size of
the initial term, validating its design. The study highlights two distinguished
features of strong machines, namely backtracking phases and their interactions
with abstractions and environments.Comment: Accepted at APLAS 201
Comparing Calculi of Explicit Substitutions with Eta-reduction1 1Partially supported by the Brazilian CNPq research council grant number 47488101-6.
AbstractThe past decade has seen an explosion of work on calculi of explicit substitutions. Numerous work has illustrated the usefulness of these calculi for practical notions like the implementation of typed functional programming languages and higher order proof assistants. Three styles of explicit substitutions are treated in this paper: the 位蟽 and the 位se which have proved useful for solving practical problems like higher order unification, and the suspension calculus related to the implementation of the language 位-Prolog. We enlarge the suspension calculus with an adequate eta-reduction which we show to preserve termination and confluence of the associated substitution calculus and to correspond to the eta-reductions of the other two calculi. Additionally, we prove that 位蟽 and 位se as well as 位蟽 and the suspension calculus are non comparable while 位se is more adequate than the suspension calculus
From Interpreter to Compiler and Virtual Machine: A Functional Derivation
We show how to derive a compiler and a virtual machine from a compositional interpreter. We first illustrate the derivation with two evaluation functions and two normalization functions. We obtain Krivine's machine, Felleisen et al.'s CEK machine, and a generalization of these machines performing strong normalization, which is new. We observe that several existing compilers and virtual machines--e.g., the Categorical Abstract Machine (CAM), Schmidt's VEC machine, and Leroy's Zinc abstract machine--are already in derived form and we present the corresponding interpreter for the CAM and the VEC machine. We also consider Hannan and Miller's CLS machine and Landin's SECD machine. We derived Krivine's machine via a call-by-name CPS transformation and the CEK machine via a call-by-value CPS transformation. These two derivations hold both for an evaluation function and for a normalization function. They provide a non-trivial illustration of Reynolds's warning about the evaluation order of a meta-language
A Symmetric Approach to Compilation and Decompilation
Just as specializing a source interpreter can achieve compilation from a source language to a target language, we observe that specializing a target interpreter can achieve compilation from the target language to the source language. In both cases, the key issue is the choice of whether to perform an evaluation or to emit code that represents this evaluation. We substantiate this observation by specializing two source interpreters and two target interpreters. We first consider a source language of arithmetic expressions and a target language for a stack machine, and then the lambda-calculus and the SECD-machine language. In each case, we prove that the target-to-source compiler is a left inverse of the source-to-target compiler, i.e., it is a decompiler. In the context of partial evaluation, compilation by source-interpreter specialization is classically referred to as a Futamura projection. By symmetry, it seems logical to refer to decompilation by target-interpreter specialization as a Futamura embedding
Distilling Abstract Machines (Long Version)
It is well-known that many environment-based abstract machines can be seen as
strategies in lambda calculi with explicit substitutions (ES). Recently,
graphical syntaxes and linear logic led to the linear substitution calculus
(LSC), a new approach to ES that is halfway between big-step calculi and
traditional calculi with ES. This paper studies the relationship between the
LSC and environment-based abstract machines. While traditional calculi with ES
simulate abstract machines, the LSC rather distills them: some transitions are
simulated while others vanish, as they map to a notion of structural
congruence. The distillation process unveils that abstract machines in fact
implement weak linear head reduction, a notion of evaluation having a central
role in the theory of linear logic. We show that such a pattern applies
uniformly in call-by-name, call-by-value, and call-by-need, catching many
machines in the literature. We start by distilling the KAM, the CEK, and the
ZINC, and then provide simplified versions of the SECD, the lazy KAM, and
Sestoft's machine. Along the way we also introduce some new machines with
global environments. Moreover, we show that distillation preserves the time
complexity of the executions, i.e. the LSC is a complexity-preserving
abstraction of abstract machines.Comment: 63 page
A Rational Deconstruction of Landin's SECD Machine with the J Operator
Landin's SECD machine was the first abstract machine for applicative
expressions, i.e., functional programs. Landin's J operator was the first
control operator for functional languages, and was specified by an extension of
the SECD machine. We present a family of evaluation functions corresponding to
this extension of the SECD machine, using a series of elementary
transformations (transformation into continu-ation-passing style (CPS) and
defunctionalization, chiefly) and their left inverses (transformation into
direct style and refunctionalization). To this end, we modernize the SECD
machine into a bisimilar one that operates in lockstep with the original one
but that (1) does not use a data stack and (2) uses the caller-save rather than
the callee-save convention for environments. We also identify that the dump
component of the SECD machine is managed in a callee-save way. The caller-save
counterpart of the modernized SECD machine precisely corresponds to Thielecke's
double-barrelled continuations and to Felleisen's encoding of J in terms of
call/cc. We then variously characterize the J operator in terms of CPS and in
terms of delimited-control operators in the CPS hierarchy. As a byproduct, we
also present several reduction semantics for applicative expressions with the J
operator, based on Curien's original calculus of explicit substitutions. These
reduction semantics mechanically correspond to the modernized versions of the
SECD machine and to the best of our knowledge, they provide the first syntactic
theories of applicative expressions with the J operator
An Operational Foundation for Delimited Continuations in the CPS Hierarchy
We present an abstract machine and a reduction semantics for the lambda-calculus extended with control operators that give access to delimited continuations in the CPS hierarchy. The abstract machine is derived from an evaluator in continuation-passing style (CPS); the reduction semantics (i.e., a small-step operational semantics with an explicit representation of evaluation contexts) is constructed from the abstract machine; and the control operators are the shift and reset family. At level n of the CPS hierarchy, programs can use the control operators shift_i and reset_i for