Questions tagged [continuations]

In computer science and programming, a continuation is an abstract representation of the control state. A continuation reifies an instance of a computational process at a given point in the process's execution. It contains information such as the process's current stack (including all data whose lifetime is within the process e.g. "local variables"), as well the process's point in the computation.

Using continuation, when a function calls another function, that is the last thing it does. An extra argument is part of every function, which will be used to pass each function's continuation. Instead of waiting for the called function to return, it puts any work it wants to do afterwards into a continuation, which it passes to the function. Essentially, this involves breaking up the code into a collection of callback functions.

501 questions
150
votes
3 answers

Coroutine vs Continuation vs Generator

What is the difference between a coroutine and a continuation and a generator ?
Mehdi Asgari
  • 1,931
  • 3
  • 15
  • 17
142
votes
3 answers

What's the difference between a continuation and a callback?

I've been browsing all over the web in search of enlightenment about continuations, and it's mind boggling how the simplest of explanations can so utterly confound a JavaScript programmer like myself. This is especially true when most articles…
Aadit M Shah
  • 67,342
  • 26
  • 146
  • 271
85
votes
7 answers

What are Scala continuations and why use them?

I just finished Programming in Scala, and I've been looking into the changes between Scala 2.7 and 2.8. The one that seems to be the most important is the continuations plugin, but I don't understand what it's useful for or how it works. I've seen…
Dave
  • 7,229
  • 12
  • 33
  • 42
81
votes
2 answers

Is Async await keyword equivalent to a ContinueWith lambda?

Could someone please be kind enough to confirm if I have understood the Async await keyword correctly? (Using version 3 of the CTP) Thus far I have worked out that inserting the await keyword prior to a method call essentially does 2 things, A. It…
Maxim Gershkovich
  • 42,124
  • 39
  • 134
  • 227
80
votes
5 answers

How and why does the Haskell Cont monad work?

This is how the Cont monad is defined: newtype Cont r a = Cont { runCont :: (a -> r) -> r } instance Monad (Cont r) where return a = Cont ($ a) m >>= k = Cont $ \c -> runCont m $ \a -> runCont (k a) c Could you explain how and why this…
monb
  • 801
  • 7
  • 3
63
votes
1 answer

Use MonadRef to implement MonadCont

There is a well known issue that we cannot use forall types in the Cont return type. However it should be OK to have the following definition: class Monad m => MonadCont' m where callCC' :: ((a -> forall b. m b) -> m a) -> m a shift ::…
Earth Engine
  • 9,100
  • 4
  • 41
  • 68
59
votes
5 answers

Async/Await - is it *concurrent*?

I've been considering the new async stuff in C# 5, and one particular question came up. I understand that the await keyword is a neat compiler trick/syntactic sugar to implement continuation passing, where the remainder of the method is broken up…
Neil Barnwell
  • 38,622
  • 28
  • 141
  • 213
54
votes
10 answers

What is call/cc?

I've tried several times to grasp the concept of continuations and call/cc. Every single attempt was a failure. Can somebody please explain me these concepts, ideally with more realistic examples than these on Wikipedia or in other SO posts. I have…
Michał Niedźwiedzki
  • 12,483
  • 7
  • 41
  • 47
53
votes
12 answers

How to implement continuations?

I'm working on a Scheme interpreter written in C. Currently it uses the C runtime stack as its own stack, which is presenting a minor problem with implementing continuations. My current solution is manual copying of the C stack to the heap then…
Kyle Cronin
  • 72,761
  • 40
  • 144
  • 160
43
votes
2 answers

Help understanding Continuations in Scheme

I have been working alongside The Little Schemer to learn Scheme and using PLT-Scheme for my environment. The Little Schemer has helped me tremendously with recursion (it is straightforward for me now) but I'm stuck on a portion of the book that…
Ixmatus
  • 1,041
  • 9
  • 15
36
votes
2 answers

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

From this thread (Control.Monad.Cont fun, 2005), Tomasz Zielonka introduced a function (commented in a clear and nice manner by Thomas Jäger). Tomasz takes the argument (a function) of a callCC body and returns it for later usage with the following…
makelc
  • 857
  • 8
  • 9
33
votes
2 answers

Why are delimited continuation primitives named "shift" and "reset"?

I think I understand (in general) what shift and reset mean. However I do not understand why they are named so ? What do shift and reset as Delimited Continuation primitives have to do with "shift" and "reset" words in English?
Michael
  • 9,937
  • 10
  • 55
  • 105
33
votes
9 answers

I just don't get continuations!

What are they and what are they good for? I do not have a CS degree and my background is VB6 -> ASP -> ASP.NET/C#. Can anyone explain it in a clear and concise manner?
Oded
  • 463,167
  • 92
  • 837
  • 979
32
votes
5 answers

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

We have a very high performance multitasking, near real-time C# application. This performance was achieved primarily by implementing cooperative multitasking in-house with a home grown scheduler. This is often called micro-threads. In this system…
Wayne
  • 2,903
  • 2
  • 27
  • 46
32
votes
1 answer

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

Are there any rules of thumb for when to use continuation-passing style vs codensity vs reflection without remorse when creating monads in Haskell? As an example, I'm going to use a simple coroutine monad. If you've never seen this before, you might…
illabout
  • 3,148
  • 16
  • 37
1
2 3
33 34