# Revisiting coroutines

@article{Moura2009RevisitingC,
title={Revisiting coroutines},
author={Ana L{\'u}cia de Moura and Roberto Ierusalimschy},
journal={ACM Trans. Program. Lang. Syst.},
year={2009},
volume={31},
pages={6:1-6:31}
}
• Published 2009
• Computer Science
• ACM Trans. Program. Lang. Syst.
This article advocates the revival of coroutines as a convenient general control abstraction. After proposing a new classification of coroutines, we introduce the concept of full asymmetric coroutines and provide a precise definition for it through an operational semantics. We then demonstrate that full coroutines have an expressive power equivalent to one-shot continuations and one-shot delimited continuations. We also show that full asymmetric coroutines and one-shot delimited continuations… Expand

#### Figures and Topics from this paper

A verified abstract machine for functional coroutines
This article presents a refinement of de Groote’s abstract machine for functional coroutines and proves its correctness, which provides a direct computational interpretation of the Constant Domain logic. Expand
On the Soundness of Coroutines with Snapshots
• Computer Science
• ArXiv
• 2018
This paper develops a formal model called $\lambda_{\rightsquigarrow}$ (lambda-squiggly) that captures the essence of type-safe, stackful, delimited coroutines with snapshots, and proves the standard progress and preservation safety properties. Expand
Typing Coroutines
• Computer Science
• Trends in Functional Programming
• 2010
This work supplies the first type system with dedicated support for coroutines, based on the simply-typed lambda calculus extended with effects that describe control transfers between cor outines. Expand
Coroutines with Higher Order Functions
This short paper proposes a very simple way to implement coroutine-like components on the top of any language that support or can emulate higher order functions. Expand
Deriving Type Systems and Implementations for Coroutines
Starting from reduction semantics for several styles of coroutines from the literature, we apply Danvy’s method to obtain equivalent functional implementations (definitional interpreters) for them.Expand
Towards Deriving Type Systems and Implementations for Coroutines
• Computer Science
• APLAS
• 2010
Starting from reduction semantics for several styles of coroutines from the literature, Danvy's method is applied to obtain equivalent functional implementations (definitional interpreters) for them and sound type systems are obtained through the translation. Expand
One-Shot Algebraic Effects as Coroutines
• Computer Science
• TFP
• 2020
A translation from algebraic effects and handlers to asymmetric coroutines is presented, which provides a simple, efficient and widely applicable implementation for the former and its embedding as a library in Lua and Ruby allows one to write effectful programs in a modular way using algebraiceffects and handlers. Expand
QEMU/CPC: static analysis and CPS conversion for safe, portable, and efficient coroutines
• Computer Science
• PEPM '14
• 2014
This work proposes a new type of annotations to identify functions which never cooperate, and introduces CoroCheck, a tool for the static analysis and inference of cooperation annotations, and improves the CPC translator, which is applied to QEMU, an open-source machine emulator which also uses annotated coroutine functions for concurrency. Expand
Theory and Practice of Coroutines with Snapshots
• Computer Science
• ECOOP
• 2018
This work introduces first-class, type- safe, stackful coroutines with snapshots, which unify many variants of suspendable computing and develops a formal model for type-safe, stackFUL and delimited cor outines, which is sufficiently general to express iterators, single-assignment variables, async-await, actors, event streams, backtracking, symmetric coroutine and continuations. Expand
A practical type system for safe aliasing
• Computer Science
• SLE
• 2018
This paper proposes a type system that relaxes the usual single-writer constraint for single threaded programs, without sacrificing race safety properties, in the form of a simple reference-based language, for which the author provides a formal semantics, as well as an interpreter. Expand

#### References

SHOWING 1-10 OF 68 REFERENCES
Coroutines in Lua
• Computer Science
• 2004
This paper presents and discusses the corou- tine facilities provided by the language Lua, a full implementation of the concept of asymmetric coroutines, and shows that this powerful construct supports easy and succint implementations of useful control behaviors. Expand
Stores and partial continuations as first-class objects in a language and its environment
• Computer Science
• POPL '88
• 1988
Abstraction, Iike the semantics of integers above, simply applies the continuation to the extant store and a semantic cognate of the (syntactic)1 abstraction. Expand
Iteration abstraction in Sather
• Computer Science
• TOPL
• 1996
Sather extends the notion of an iterator in a powerful new way. We argue that iteration abstractions belong in class interfaces on an equal footing with routines. Sather iterators were derived fromExpand
Obtaining Coroutines with Continuations
• Computer Science
• Comput. Lang.
• 1986
The power of first class continuations is demonstrated by implementing a variety of coroutine mechanisms using only continuations and functional abstraction. Expand
• Computer Science
• LISP Symb. Comput.
• 1998
This article describes current implementation of one-shot subcontinuations, a novel feature of the implementation is that continuations are implemented in terms ofthreads, and is applicable to any language or language implementation that supports a small set of threadprimitives. Expand
Abstracting control
• Computer Science
• LISP and Functional Programming
• 1990
This article investigates an alternative formulation of continuations, exploiting the latent expressive power of the standard continuation-passing style (CPS) instead of introducing yet other new concepts, and describes an improved conversion into applicative-order CPS. Expand
The theory and practice of first-class prompts
With the introduction of prompt-applications, the control calculus becomes a traditional calculus all of whose equations imply operational equivalence and enhance the expressiveness and efficiency of the language. Expand
Embedding continuations in procedural objects
• Computer Science
• TOPL
• 1987
This work considers techniques for constraining the power of continuations in the interest of security and efficiency, and presents two mechanisms, wind-unwind and dynamic-wind, that generalize unwind-protect. Expand
Handling control
It is invoked that all denotational models of control languages invariably include capabilities that handle control, and these capabilities form an elegant and powerful higher-order generalization of the first-order exception-handling mechanism. Expand
Engines From Continuations
• Computer Science
• Comput. Lang.
• 1989
The article extends the engine mechanisms to solve several problems with nestable engines, and demonstrates that the extended mechanism can be implemented in terms of continuations as well. Expand