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.

535 questions
9
votes
3 answers

CPS in curried languages

How does CPS in curried languages like lambda calculus or Ocaml even make sense? Technically, all function have one argument. So say we have a CPS version of addition in one such language: cps-add k n m = k ((+) n m) And we call it like (cps-add…
Zorf
  • 6,334
  • 2
  • 29
  • 24
9
votes
2 answers

Cont monad shift

While trying to build some intuition for the ContT monad transformer I (perhaps unsurprisingly) found myself confused. The issue lies with the shiftT operation which doesn't seem to do anything useful. First a simplistic example of how one might use…
Taren
  • 674
  • 5
  • 11
9
votes
2 answers

continuations as meaningful comprehensions

Monads may be construed as forms of containers: list : aggregation of items from a given type bag : unordered aggregation set : unordered aggregation that ignores multiplicity Maybe : aggregation of at-most one item Reader e : aggregations of…
Musa Al-hassy
  • 982
  • 1
  • 7
  • 12
9
votes
2 answers

Update text box on continuation with Winforms and C#

C# noob here, coming from experience in other languages. (Most notably Java). I'm looking at this question's code. It's a standard WinForms C# project in VS 2013: drop a button and a textbox on the form and use this code: private void…
kdbanman
  • 10,161
  • 10
  • 46
  • 78
9
votes
3 answers

interpret Parigot's lambda-mu calculus in Haskell

One can interpret the lambda calculus in Haskell: data Expr = Var String | Lam String Expr | App Expr Expr data Value a = V a | F (Value a -> Value a) interpret :: [(String, Value a)] -> Expr -> Value a interpret env (Var x) = case lookup x env…
Bob
  • 1,713
  • 10
  • 23
9
votes
2 answers

What are Haskell continuation based web framework?

Occasionally I encounter the notion of continuation based web frameworks for Haskell. What does that mean exactly? Continuations as I know them are gloried goto control structures. I fail to see how they relate to web stuff. What exactly would using…
user782220
  • 10,677
  • 21
  • 72
  • 135
9
votes
1 answer

What's the relationship between the async/await pattern and continuations?

I'm wondering what's the relationship between the async/await pattern (as known from Scala, F#, C#, etc.) and continuations: Is the async/await pattern a limited subset of full-blown continuations? (If true, how are continuations more…
soc
  • 27,983
  • 20
  • 111
  • 215
9
votes
2 answers

What exactly are administrative redexes after CPS conversion?

In the context of Scheme and CPS conversion, I'm having a little trouble deciding what administrative redexes (lambdas) exactly are: all the lambda expressions that are introduced by the CPS conversion only the lambda expressions that are…
eljenso
  • 16,789
  • 6
  • 57
  • 63
9
votes
1 answer

Using Scala continuations with while loops

I realize this is counter to the usual sense of SO questions, but the following code works even though I think it should not work. Below is a small Scala program that uses continuations with a while loop. According to my understanding of…
jcrudy
  • 3,921
  • 1
  • 24
  • 31
8
votes
2 answers

TPL and Exception Handling

All, there are many question on the above topic but I believe this is sufficiently different to warrant a new question. I have the following Task and a continuation to deal with a variety of task Status; TaskStatus.RanToCompletion,…
MoonKnight
  • 23,214
  • 40
  • 145
  • 277
8
votes
1 answer

Can I copy a function with its *current* state?

Raku's state declarator can be used to give a subroutine or other block its own local state that persists across multiple invocations of the function: sub f { state $n++ } say f; # OUTPUT: «0» say f; # OUTPUT: «1» say f; # OUTPUT: «2» I'm aware of…
codesections
  • 8,900
  • 16
  • 50
8
votes
3 answers

Is Rhino the only interpreter with support for sandboxing and serializable continuations?

I need (a) sandboxing, and (b) serializeable continuations. I'm exposing server-side game scripting to users, and it is extremely async, thus the callback pattern makes code un-readable and very un-approachable for newbie programmers. A…
Lilith River
  • 16,204
  • 2
  • 44
  • 76
8
votes
1 answer

Reacting to Task completion: `.ContinueWith()` vs `GetAwaiter().OnCompleted()`

Say I have a Task that generates an int, and a callback that accepts an int: Task task = ...; Action f = ...; Now I want to set it up so that once the task has completed and returned its integer result, the callfack f will be called with…
smls
  • 5,738
  • 24
  • 29
8
votes
1 answer

What's the benefit of scalaz.concurrent.Future, in comparison to scalaz.ContT[Trampoline, Unit, ?]

I was looking for a data type for asynchronous operations. I found that scalaz.ContT[Trampoline, Unit, ?] supports all features in scalaz.concurrent.Future, in addition of BindRec. Though, there are more utilities for scalaz.concurrent.Future than…
Yang Bo
  • 3,586
  • 3
  • 22
  • 35
8
votes
2 answers

Is ContinueWith guaranteed to execute?

I've got a bit of code that is acting as a light weight, non-blocking, critical section. I am hoping that no matter what happens with _func and cancellationToken in the Task.Run clause, that the continuation is guaranteed to run such that the Exit…
dkackman
  • 15,179
  • 13
  • 69
  • 123