Questions tagged [delimited-continuations]

A delimited continuation is a "slice" of a continuation frame that has been reified into a function

A delimited continuation is a "slice" of a continuation frame that has been reified into a function. Unlike regular continuations, delimited continuations return a value, and thus may be reused and composed.

44 questions
5
votes
1 answer

Understanding shift/reset in Racket

I present two naive implementations of foldr in racket This first one lacks a proper tail call and is problematic for large values of xs (define (foldr1 f y xs) (if (empty? xs) y (f (car xs) (foldr1 f y (cdr xs))))) (foldr1 list 0 '(1…
Mulan
  • 129,518
  • 31
  • 228
  • 259
5
votes
1 answer

How do I use Agda's implementation of delimited continuations?

We can implement a delimited continuation monad in Agda rather easily. There is, however, no need to, as the Agda "standard library" has an implementation of a delimited continuation monad. What confuses me about this implementation, though, is the…
wen
  • 3,782
  • 9
  • 34
  • 54
5
votes
1 answer

Understanding the API of multi-prompt delimited continuations

An API for multi-prompt delimited continuations is described in the paper Delimited Control in OCaml, Abstractly and Concretely System Description. My question concerns the type of push_subcont : ('a,'b) subcont -> (unit -> 'a) -> 'b. Why is this…
Jules
  • 6,318
  • 2
  • 29
  • 40
4
votes
2 answers

Scala: Delimited Continuations Explained - Not

Interested in the concept of continuation, I started reading wikis, posts, and came to this "simple" example: reset { ... shift { k: (Int=>Int) => // the continuation k will be the '_ + 1' below k(7) } + 1 } // result: 8 Without…
athos
  • 6,120
  • 5
  • 51
  • 95
4
votes
2 answers

How to extract delimited continuation (reset/shift) for future use in Haskell?

The following is a simple example of using delimited continuation (reset/shift): import Control.Monad import Control.Monad.Trans import Control.Monad.Trans.Cont test :: Integer test = evalCont . reset $ do r <- shift $ \k -> do return $…
chansey
  • 1,266
  • 9
  • 20
4
votes
2 answers

Does it matter where a shift stands in a reset block?

Suppose, there is a reset block with a single shift: val r = reset { // do smth. 1 shift {...} // do smth. 2 // do smth. 3 } Is it correct that I place the shift after "do smth. 2" or "do smth. 3" without changing the result r? Is it…
Michael
  • 10,185
  • 12
  • 59
  • 110
4
votes
1 answer

How to discard a delimited continuation from within multiple nested functions?

I study delimited continuations and am currently playing with discarding them to obtain an effect similar to raising exceptions. Here is what causes me trouble: const structure = type => cons => { const f = (f, args) => ({["run" + type]: f,…
4
votes
1 answer

Practical Delimited Continuations in C / x64 ASM

I've look at a paper called A Primer on Scheduling Fork-Join Parallelism with Work Stealing. I want to implement continuation stealing, where the rest of the code after calling spawn is eligible to be stolen. Here's the code from the paper. 1 e(); 2…
Jesse Lactin
  • 301
  • 3
  • 12
4
votes
3 answers

Implement yield and send in Scheme

I'm trying to port yield and yield from from Python to Scheme. Here is an implementation I've done: (define (coroutine routine) (let ((current routine) (status 'new)) (lambda* (#:optional value) (let ((continuation-and-value …
amirouche
  • 7,682
  • 6
  • 40
  • 94
4
votes
1 answer

nested CPS "reset"

using the CPS compiler-plugin of Scala 2.8, there are the two magic controls reset and shift. Reset delimits the continuation and shift captures the continuation. There is an example of using CPS with NIO, using nested resets as a type of…
3
votes
0 answers

How to implement a coroutine based on multi-shot delimited continuations?

I recently implemented delimited continuations in CPS with reset/shift: // reset :: ((a -> a) -> a) -> (a -> r) -> r reset = k => f => f(k(id)); // shift :: ((a -> r) -> (r -> r) -> r) -> (a -> r) -> r shift = f => k => f(k) (id); Studying the…
3
votes
2 answers

Are continuations in Kotlin usable yet? Any examples available?

There is an package in Kotlin for continuations, but it's marked as experimental. There is no documentation other than the API, and no tutorial or examples anywhere that I could find. Does anyone know if it's already usable? What would be an example…
3
votes
2 answers

What does a continuation return in Scheme?

I came across something that I can not understand. #lang scheme (define cc #f) (define (val!) (call/cc (lambda (k) (set! cc k) 0))) (* 10 (val!)) (cc 100) So far so good; the continuation of (* 10 []) is stored in cc and if we…
user3597931
3
votes
0 answers

Are there interesting single-shot monads besides Maybe and Either?

In the Monte programming language, as well as in its ancestor E, there is syntax for single-shot delimited continuations, called "ejectors," which are continuations that are effectively only usable once within a syntactic boundary. For example, here…
Corbin
  • 1,530
  • 1
  • 9
  • 19
2
votes
1 answer

Translating call/comp to equivalent CPS style in JS

I read lots of article already on how to translate call/cc into equivalent CPS style and kinda know the basic already but currently I don't understand how racket perform transformation with call/comp (a.k.a call-with-composable-continuation) and…