Continuations are the work that was going to be done. In a low level view, the contents of the stack, registers, and program counter are enough. Capturing all that is a pain, but it can be done. The system call fork for example kind of copies all of that brute force. Depending how you write an interpreter, the capturing the work to be done can be tricky. Very often we write interpreters using recursive function calls. We are borrowing the host language stack to hold work to be done. If you explicitly manage the interpreter stack, it becomes more clear how to talk about the continuation.

Relationship between monads and continuations

mother of all monads. Buyt also Filinkski paper. refiication and reflection - In a langue with effects like ocaml, we can reflect / reify the exceptions or mutation into their pure form that uses monad dsiciplaine. Converting native ocaml exception to Either exceptions some caustic yet intriguing discussion. The embedding is (x »=) like how cps embedding is (x $)? This is interesting. Using cont monad in swift probably to deal with the lack of higher kinded types. Similar to rust problem

Contexts and Holes

Are continuations functions?

Mostly no.

standard ml contiutation signature

type 'a cont
val callcc : ('a cont -> 'a) -> 'a
val throw : 'a cont -> 'a -> 'b
val isolate : ('a -> unit) -> 'a cont
type 'a control_cont
val capture : ('a control_cont -> 'a) -> 'a
val escape : 'a control_cont -> 'a -> 'b

throw is apply. The question is do we really want cont and (->) to be interchangeable. In a CPS implementation, the are

The stack as a closure

A closure is an value that contains a code pointer and captured data. To invoke a closure, you need to know some things about it’s layout, but not everything. It hides it’s implementation. Closures are objects in this sense.

Closures sometimes only store minimal amounts of environment, but in a naive implementation can store much more, maybe a copy of every variable in local scope for example instead of just the variables it closes over.

The conventional C stack has a return address and all the context of what has been going on. This really is a function pointer and environment. It is a closure. This closure however does not rely on the garbage collector to reclaim its memory, but so what?

Delimitted Continuations

Oleg delimcc an implemntation of delimitted continuations for the This uses exceptions (trap frames) as stack markers. In ocaml, at every try block puts handlers in the stack. These are marks It then copies the stack up to these points. mentions camlcallcc by xavier leroy It’s pretty small actually. Very interesting. It is copying the stack quite literally.

A delimitted continuation is a mapping between contexts… ? lwt fibers using delimcc

libmprompt A 64-bit C/C++ library that aims to implement robust and efficient multi-prompt delimited control.

Continuations Prompts

Marks racket docs on conituation karks Compiler and runtik support for continuation marks The stack exists. You can put marks on it that could be searched for.

One Shot

One shot continuationns can be called at most or exactly once. This is simpler and more efficient to implement and covers many (but not all) use cases



call with current continuation Relationship to double negation encoding

An argument against call-cc undelimited continuations are covalues rather than functions


Algebraic effects

The Evolution of Effects (Keynote) - Wu What even are algebraic effects?

Kind of like resumable exceptions. Also kind of like yield-step (exactly like?).

Koka Generalized evidence passing for effect handlers: efficient compilation of effect handlers to C Implementing Algebraic Effects in C libhandler

Interaction trees. THe semantics of a program is a tree of call and response patterns. THe handler is a fold over the tree giving it semantics

High-Level Effect Handlers in C++


Either Err a piggy backs error handling on the regular return mechanisms. Every stack frame needs to be inspected to bubble error up. This is not how native ocaml exceptions are implemented and probably not how many systems do it.

CPS piggybacks other control flow on closure creation mechanisms.

Ocaml is getting an effect system See my ocaml notes for more.

  • Efficient compilation of algebraic effect handlers
  • effectfuljs. a javascrpt transpiler for effects very cool. multi prompt delim conitautiona too?
  • effect systems are off to the side, but do they help explain lifetimes? interesting commments. Oleg talk. Frank language
  • divergence as an effect. But also is memory usage an effect
  • ocaml algebraic effects.
  • There was an andrej bauer video What’s Algebraic About Algebraic Effects and Handlers?
  • Sandy Maguire and polysemy
  • resumable exceptions.
  • Related the the python yield stuff.
  • Daan Leijen paper comes up
  • Koka, Eff, F*, Link, Helium
  • Daan Leijen Asynchrony with Algerbaic Effects
  • Plotkin papers
  • Alexis King effects for less
  • delimitted continuation primops ghc proposal. Lots of interestnig discussion
  • Pretnar 2015 An Introduction to Algebraic Effects and Handlers Invited tutorial pap
  • delimitted contiunuations
  • Asai
  • Eff directly in ocaml Kiselyov Sivaramakrishnan
  • algerbaic effects for the rest of us async functions and generators have a different “color”. effects remove the need for this how? common lisp condition system is related? Is another example of resumable exceptions.


srfi 226: Control Features

Coroutines and generators as effect systems. javascript cotuotines to conitations

Rebvisting coroutines Yield - mainstream delimitted continuations. slides Lazy v Yield - kiselyov sabry peytonjones Inremental linear pretty printing probablistic programming,It%20supports%203.6%20and%20above. effect - as python library

takafumi asrakaki using julia yieldto for a “callcc” Anatomy of Lisp. Lisp in small pieces.

Lambda prolog book is drectly talking about semantics in terms of sequents Jones forth tutorail assembly The essence of compiling with continuations. Pushing A normal form.