Typing Composable Coroutines

08/21/2023
by   Qiqi Gu, et al.
0

Coroutine, as a powerful programming construct, is widely used in asynchronous applications to replace thread-based programming or the callback hell. Using coroutines makes code more readable and maintainable, for its ability to transfer control while keeping the literal scope. However, reasoning about coroutine behavior can be challenging without proper typing. We propose a type notation and calculus for composing asymmetric, first-class, stackless coroutines. Given the types of a list of coroutines, we can compute a composed type matching the collective behavior of the coroutines, so that the input and output can be type-checked by a type system. Our coroutine types can model the data received by or yielded from a coroutine, which be of coroutine types as well. On top of our type calculus, we discuss its soundness and evaluation issues, then provide four application scenarios of our coroutine types. Not only can our types be used in modern programming languages, such as Python, but also model program behaviors in OCaml and even Prolog.

READ FULL TEXT

page 1

page 2

page 3

page 4

research
10/03/2019

Types for Parallel Complexity in the Pi-calculus

Type systems as a way to control or analyze programs have been largely s...
research
11/23/2022

Data-Codata Symmetry and its Interaction with Evaluation Order

Data types and codata types are, as the names suggest, often seen as dua...
research
09/15/2022

A case for DOT: Theoretical Foundations for Objects With Pattern Matching and GADT-style Reasoning

Many programming languages in the OO tradition now support pattern match...
research
03/29/2021

A simpler encoding of indexed types

In functional programming languages, generalized algebraic data types (G...
research
03/15/2023

Transformer Models for Type Inference in the Simply Typed Lambda Calculus: A Case Study in Deep Learning for Code

Despite a growing body of work at the intersection of deep learning and ...
research
06/17/2015

Pragmatic Side Effects

In the quest to give a formal compositional semantics to natural languag...
research
07/02/2019

Local Reasoning for Robust Observational Equivalence

We propose a new core calculus for programming languages with effects, i...

Please sign up or login with your details

Forgot password? Click here to reset