Capturing the Future by Replaying the Past

10/28/2017
by   James Koppel, et al.
0

Delimited continuations are the mother of all monads! So goes the slogan inspired by Filinski's 1994 paper, which showed that delimited continuations can implement any monadic effect, letting the programmer use an effect as easily as if it was built into the language. It's a shame that not many languages have delimited continuations. Luckily, exceptions and state are also the mother of all monads! In this Pearl, we show how to implement delimited continuations in terms of exceptions and state, a construction we call thermometer continuations. While traditional implementations of delimited continuations require some way of "capturing" an intermediate state of the computation, the insight of thermometer continuations is to reach this intermediate state by replaying the entire computation from the start, guiding it using a "replay stack" it so that the same thing happens until the captured point. Along the way, we explain delimited continuations and monadic reflection, show how the Filinski construction lets thermometer continuations express any monadic effect, share an elegant special-case for nondeterminism, and discuss why our construction is not prevented by theoretical results that exceptions and state cannot macro-express continuations.

READ FULL TEXT
research
05/20/2021

Indirect predicates for geometric constructions

Geometric predicates are a basic ingredient to implement a vast range of...
research
02/03/2023

The Quantum Effect: A Recipe for QuantumPi

Free categorical constructions characterise quantum computing as the com...
research
11/11/2022

A Universal Construction for Unique Sink Orientations

Unique Sink Orientations (USOs) of cubes can be used to capture the comb...
research
11/29/2018

Sequential Effect Systems with Control Operators

Sequential effect systems are a class of effect system that exploits inf...
research
11/09/2018

Post-randomization Biomarker Effect Modification in an HIV Vaccine Clinical Trial

While the HVTN 505 trial showed no overall efficacy of the tested vaccin...
research
04/20/2020

The new methods for equity fund selection and optimal portfolio construction

We relook at the classic equity fund selection and portfolio constructio...
research
12/29/2022

Transactions Make Debugging Easy

We propose TROD, a novel transaction-oriented framework for debugging mo...

Please sign up or login with your details

Forgot password? Click here to reset