Handling Bidirectional Control Flow: Technical Report

10/18/2020
by   Yizhou Zhang, et al.
0

Pressed by the difficulty of writing asynchronous, event-driven code, mainstream languages have recently been building in support for a variety of advanced control-flow features. Meanwhile, experimental language designs have suggested effect handlers as a unifying solution to programmer-defined control effects, subsuming exceptions, generators, and async–await. Despite these trends, complex control flow—in particular, control flow exhibiting a bidirectional pattern—remains challenging to manage. We introduce bidirectional algebraic effects, a new programming abstraction that supports bidirectional control transfer in a more natural way. Handlers of bidirectional effects can raise further effects to transfer control back to the site where the initiating effect was raised, and can use themselves to handle their own effects. We present applications of this expressive power, which falls out naturally as we push toward the unification of effectful programming with object-oriented programming. We pin down the mechanism and the unification formally using a core language that generalizes to effect operations and effect handlers. The usual propagation semantics of control effects such as exceptions conflicts with modular reasoning in the presence of effect polymorphism—it breaks parametricity. Bidirectionality exacerbates the problem. Hence, we set out to show the core language, which builds on the existing tunneling semantics for algebraic effects, is not only type-safe (no effects go unhandled), but also abstraction-safe (no effects are accidentally handled). We devise a step-indexed logical-relations model, and construct its parametricity and soundness proofs. These core results are fully mechanized in Coq. Preliminary experiments show that as a first-class language feature, bidirectional handlers can be implemented efficiently.

READ FULL TEXT

page 1

page 2

page 3

page 4

research
10/14/2021

Parallel Algebraic Effect Handlers

Algebraic effects and handlers support composable and structured control...
research
04/04/2023

Gradual Typing for Effect Handlers

We present a gradually typed language, GrEff, with effects and handlers ...
research
02/02/2023

A Framework for the Automated Verification of Algebraic Effects and Handlers (extended version)

Algebraic effects and handlers are a powerful abstraction to build non-l...
research
07/18/2023

Soundly Handling Linearity

We propose a novel approach to soundly combining linear types with effec...
research
04/01/2021

Retrofitting Effect Handlers onto OCaml

Effect handlers have been gathering momentum as a mechanism for modular ...
research
08/25/2021

Latent Effects for Reusable Language Components: Extended Version

The development of programming languages can be quite complicated and co...
research
07/10/2019

CallE: An Effect System for Method Calls

Effect systems are used to statically reason about the effects an expres...

Please sign up or login with your details

Forgot password? Click here to reset