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
22
votes
3 answers

Why the continuations of Task.WhenAll are executed synchronously?

I just made a curious observation regarding the Task.WhenAll method, when running on .NET Core 3.0. I passed a simple Task.Delay task as a single argument to Task.WhenAll, and I expected that the wrapped task will behave identically to the original…
Theodor Zoulias
  • 34,835
  • 7
  • 69
  • 104
22
votes
3 answers

Is Curry-Howard correspondent of double negation ((a->r)->r) or ((a->⊥)->⊥)?

Which is the Curry-Howard correspondent of double negation of a; (a -> r) -> r or (a -> ⊥) -> ⊥, or both? Both types can be encoded in Haskell as follows, where ⊥ is encoded as forall b. b. p1 :: forall r. ((a -> r) -> r) p2 :: (a -> (forall b. b))…
nushio
  • 753
  • 3
  • 12
22
votes
2 answers

Precise flow control in Haskell

The Idea Hello! I'm trying to implement in Haskell an image processing library based on dataflow ideology. I've got a problem connected to how I want to handle the flow of control. The main idea is to introduce a time. The time is a Float, which…
Wojciech Danilo
  • 11,573
  • 17
  • 66
  • 132
22
votes
4 answers

Why doesn't a primitive `call-with-current-continuations` exist in Common Lisp

Scheme offers a primitive call-with-current-continuation, commonly abbreviated call/cc, which has no equivalent in the ANSI Common Lisp specification (although there are some libraries that try to implement them). Does anybody know the reason why…
Paulo Tomé
  • 1,910
  • 3
  • 18
  • 27
21
votes
12 answers

Looking for examples of "real" uses of continuations

I'm trying to grasp the concept of continuations and I found several small teaching examples like this one from the Wikipedia article: (define the-continuation #f) (define (test) (let ((i 0)) ; call/cc calls its first function argument,…
21
votes
6 answers

call/cc in Lua - Possible?

The Wikipedia article on Continuation says: "In any language which supports closures, it is possible to write programs in continuation passing style and manually implement call/cc." Either that is true and I need to know how to do it or it is not…
PeterM
  • 1,188
  • 1
  • 10
  • 15
20
votes
3 answers

Coroutines or continuations for Web programming in Python and Ruby. Why not?

The question is: why aren't continuations (in Ruby) and coroutines (in Python) more widely used for Web programming? Server-side web programming is made difficult by the problem of preserving state between requests. Two elegant, and related,…
Luciano Ramalho
  • 1,981
  • 18
  • 22
19
votes
2 answers

Using Cont to acquire values from the future and the past

I'm writing a brainfuck interpreter in Haskell, and I came up with what I believe to be a very interesting description of a program: data Program m = Instruction (m ()) (Program m) | Control (m (Program m)) |…
Dan Burton
  • 53,238
  • 27
  • 117
  • 198
18
votes
1 answer

Idiomatic Scala translation of Kiselyov's zippers?

Oleg Kiselyov showed how to make a zipper from any traversable by using delimited continuations. His Haskell code is quite short: module ZipperTraversable where import qualified Data.Traversable as T import qualified Data.Map as M -- In the…
Mike Stay
  • 1,071
  • 8
  • 17
17
votes
4 answers

Are continuations monads?

Can continuations be said to be monads? Are they a subset of monads or are they simply a way of implementing monads? Edit: Or maybe I got it wrong and monads is a more abstract concept than continuations? (So I'm really comparing apples to oranges…
troelskn
  • 115,121
  • 27
  • 131
  • 155
17
votes
1 answer

How to Factorize Continuation Monad into Left & Right Adjoints?

As State monad can be factorized into Product (Left - Functor) and Reader (Right - Representable). Is there a way to factorize Continuation Monad? Below code is my attempt, which wont type check -- To form a -> (a -> k) -> k {-# LANGUAGE…
Pawan Kumar
  • 1,443
  • 2
  • 16
  • 30
17
votes
2 answers

Uses for Scala continuations

How are people using continuations on a larger and smaller scale in Scala? Are any parts of the Scala standard library written in CPS? Are there any major performance penalties in using continuations?
Mohamed Bana
  • 1,251
  • 2
  • 17
  • 27
16
votes
4 answers

Serialization and the Yield statement

Is it possible to serialize a method containing yield statements (or a class that contains such a method) such that when you rehydrate the class, the internal state of the generated iterator is retained?
BuddyJoe
  • 69,735
  • 114
  • 291
  • 466
16
votes
2 answers

Choosing between continuation passing style and memoization

While writing up examples for memoization and continuation passing style (CPS) functions in a functional language, I ended up using the Fibonacci example for both. However, Fibonacci doesn't really benefit from CPS, as the loop still has to run…
Abel
  • 56,041
  • 24
  • 146
  • 247
16
votes
1 answer

Continuation passing style representation of types

Suppose we have a monad, defined by return, (>>=) and the set of laws. There is a data type newtype C m a = C { unC ∷ forall r. (a → m r) → m r } also known as Codensity. C m a ≅ m a given that m is a Monad, i.e. we can write two functions to ∷…
Matvey Aksenov
  • 3,802
  • 3
  • 23
  • 45
1 2
3
35 36