[Pue17] Typeful Continuations

Revue Nationale avec comité de lecture : Journal JFLA 2017, vol. ?(?), pp. ?, 2017, (doi:?)

Auteurs: M. Puech

Mots clés: CPS, continuations, OCaml, typeful, GADT

Résumé: Continuation-passing style translations, or CPS, are used notably in compilers. They make a functional program more explicit by sequentializing its computations and reifying its control. They have been used as an intermediate language in many compilers. Yet, we cannot directly use Plotkin’s original CPS translation to design compilers, for several reasons: i) the resulting terms it produces are verbose (they contain “administrative redexes”, a well-studied problem) and inefficient (they perform nested beta-reductions sequentially); and ii) their loose syntax can hide possible further optimizations, in particular tail call elimination. These issues have been solved in isolation and on paper, but never combined together and formalized, which i) is necessary to scale to safe, full-featured optimizing compilers and ii) is not a mere juxtaposition of the techniques but requires insight on the design of CPS translations themselves. We propose to design and implement in OCaml a compacting, optimizing CPS translation, while using OCaml’s type system to verify that it maps well-typed terms to welltyped terms in a tightly restricted syntactical form (the “typeful” approach to formalization). The resulting artifact can be used directly to design optimizing compilers, and the path towards it offers a tutorial on optimizing CPS translations, and yet another use case for OCaml’s advanced type system.


@article {
title="{Typeful Continuations}",
author="M. Puech",
journal="JFLA 2017",