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

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.



call with current continuation Relationship to double negation encoding

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


Algebraic effects

What even are algebraic effects?

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


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
  • 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.


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.