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
12
votes
10 answers

Design Pattern Alternative to Coroutines

Currently, I have a large number of C# computations (method calls) residing in a queue that will be run sequentially. Each computation will use some high-latency service (network, disk...). I was going to use Mono coroutines to allow the next…
jameszhao00
  • 7,213
  • 15
  • 62
  • 112
11
votes
1 answer

Did I just write a continuation?

I don't have formal knowledge of continuations, and am wondering if someone can help me verify and understand the code I wrote :). Problem The general problem I'm trying to solve is to convert expressions like (2 * var) + (3 * var) == 4 into…
gatoatigrado
  • 16,580
  • 18
  • 81
  • 143
11
votes
1 answer

Using Scala continuations for non-blocking APIs

I'm trying to use Scala (2.9.0) continuations to build a seemingly blocking API, but that actually is asynchronous. Suppose that you would like to write something like: if(ask("Continue?")) //Prompts Yes/No name = input("Enter your name") Where…
juancn
  • 2,483
  • 2
  • 20
  • 25
11
votes
0 answers

Is there something like a continuation Arrow transformer?

The ContT monad transformer has a interesting property: If there is a * -> * type such as Set, that has well-defined monadic operations, but can't have a Monad instance due to some constraints (here Ord a), it's possible to wrap it in ContT (ContT r…
Petr
  • 62,528
  • 13
  • 153
  • 317
11
votes
1 answer

Using Scala's Delimited Continuations for implicit Monads

I'm playing with some kind of DSL defined by an monadic interface. Since applying the monad using a bunch of flatMap applications is kind of cumbersome and I find for-comprehension syntactically not that beautiful, I'm trying to implicitely mix…
urso
  • 924
  • 1
  • 7
  • 17
11
votes
1 answer

Function signature for returning a recursive closure

I am attempting to implement a function that returns a recursive closure., though I am not sure how to express that in the function signature. Here is example code of a working implementation in Python def counter(state): def handler(msg): …
Brandon Ogle
  • 715
  • 1
  • 8
  • 23
11
votes
1 answer

The ContT Monad: Putting the pieces together

Preamble I am trying to wrap my head around how to actually use ContT and callCC for something useful. I'm having trouble following information and control flows around the the code. (but, isn't that the point of a continuation?) There are a lot of…
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
11
votes
2 answers

Cont Monad breaks laziness in Haskell

I was trying the Cont monad, and discovers the following problem. First construct a infinite list and lift all the elements to a Cont monad Use sequence operation to get a Cont monad on the infinite list. When we try to run the monad, with head,…
Shiva Wu
  • 1,074
  • 1
  • 8
  • 20
10
votes
1 answer

Continuations and for comprehensions -- what's the incompatibility?

I am new to Scala and trying to wrap my head around continuations I'm trying to reproduce the yield return C# statement. Following this post, I have written the following code : package com.company.scalatest import…
GuiSim
  • 7,361
  • 6
  • 40
  • 50
10
votes
3 answers

how can I implement this monad transformer with a continuation?

motivation. I'm trying to create a monad transformer, with a special instruction f <||> g that means "repeat this entire block containing f <||> g, once with f, the next time with g". This is intended to be for a DSL transformation, though you can…
gatoatigrado
  • 16,580
  • 18
  • 81
  • 143
10
votes
2 answers

Are continuations a key feature in Seaside?

I'm trying to get up to speed on Smalltalk / Seaside. According to Wikipedia, "Seaside is a continuation-based web application framework". Coming from a Java background I'm not very familiar with continuations. After some reading I understand…
Justin
  • 6,031
  • 11
  • 48
  • 82
10
votes
2 answers

Haskell implemented without a stack?

from How does a stackless language work? Haskell (as commonly implemented) does not have a call stack; evaluation is based on graph reduction. Really? That's interesting, because while I've never experienced it myself, I've read that if you don't…
TheIronKnuckle
  • 7,224
  • 4
  • 33
  • 56
10
votes
3 answers

Continuations in Java

I am looking for recent work presenting continuations in Java. I have come across the same question here but it dates back for a year or two. There is some work such as JavaFlow by Apache, RIFE Continuations (that I cannot download for any reason…
nobeh
  • 9,784
  • 10
  • 49
  • 66
10
votes
3 answers

Scala continuation and exception handling

Suppose, I would like to catch an exception, fix the problem caused the exception and return to the same execution point where the exception occurred to continue. How can I implement it with continuations in Scala? Does it make any sense?
Michael
  • 10,185
  • 12
  • 59
  • 110
10
votes
1 answer

Is it possible to store haskell "operational" or "free monad" continuation to disk?

I have some simple primitive operations, for example: In case of operational monad: import Control.Monad.Operational type Process a = Program ProcessI a data ProcessI a where GetInput :: ProcessI String Dump :: String -> ProcessI () getInput…