C# first class continuation via C++ interop or some other way?

There is the C# 5 CTP, which performs a continuation-passing-style transformation over methods declared with the new async keyword, and continuation-passing based calls when using the await keyword. This is not actually a new CLR feature but rather a set of directives for the compiler to perform the CPS transformation over your code and a … Read more

Constructing efficient monad instances on `Set` (and other containers with constraints) using the continuation monad

Monads are one particular way of structuring and sequencing computations. The bind of a monad cannot magically restructure your computation so as to happen in a more efficient way. There are two problems with the way you structure your computation. When evaluating stepN 20 0, the result of step 0 will be computed 20 times. … Read more

when to use CPS vs codensity vs reflection without remorse in Haskell

This problem can be broken into two pieces, how you represent the data type and how you compose them together. Data types The styles you listed use only 2 styles of data types, the “normal” style and the continuation passing style. They differ in which objects are chosen as the primitives of the language. In … Read more

Why are delimited continuation primitives named “shift” and “reset”?

They’re called so because of the way they are implemented (in general). Quoted from Direct Implementation of Shift and Reset in the MinCaml Compiler By interpreting a program using the continuation semantics, we can regard the state of the program as a continuation stack. Then, reset can be thought of as marking the continuation stack, … Read more

scheme continuations for dummies

Forget about call/cc for a moment. Every expression/statement, in any programming language, has a continuation – which is, what you do with the result. In C, for example, x = (1 + (2 * 3)); printf (“Done”); has the continuation of the math assignment being printf(…); the continuation of (2 * 3) is ‘add 1; … Read more

I just don’t get continuations!

Imagine if every single line in your program was a separate function. Each accepts, as a parameter, the next line/function to execute. Using this model, you can “pause” execution at any line and continue it later. You can also do inventive things like temporarily hop up the execution stack to retrieve a value, or save … Read more

Goto in Haskell: Can anyone explain this seemingly insane effect of continuation monad usage?

Here’s a somewhat informal answer, but hopefully useful. getCC’ returns a continuation to the current point of execution; you can think of it as saving a stack frame. The continuation returned by getCC’ has not only ContT‘s state at the point of the call, but also the state of any monad above ContT on the … Read more

What exactly is a “continuation prompt?”

What is a prompt, conceptually? Scheme in general has the idea of continuations, but Racket extends this with the idea of delimited continuations. The idea of a continuation is that it captures the remaining computation left to be evaluated. I will not attempt to explain continuations in general, since that is outside the scope of … Read more

Help understanding Continuations in Scheme

Try something simpler to see how this works. For example, here’s a version of a list-sum function that receives a continuation argument (which is often called k): (define (list-sum l k) (if (null? l) ??? (list-sum (cdr l) ???))) The basic pattern is there, and the missing parts are where the interesting things happen. The … Read more

tech