delimited-continuations

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

好久不见. 提交于 2021-02-07 14:16:00
问题 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 addition of an extra parameter to the DCont type. DCont : ∀ {i f} {I : Set i} → (I → Set f) → IFun I f DCont K = DContT K Identity My question is: why is the extra parameter K there? And how would I use the DContIMonadDCont instance? Can I open it

Scala: Delimited Continuations Explained - Not

主宰稳场 提交于 2020-01-01 06:56:58
问题 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 knowledge of Scala, I'm totally lost here, could not figure out how the 8 comes out. Below is how I tried to figure out the meaning but failed. Any guy could you please give me a short explanation? Yeah there are Scala grammar books but they are too thick, I'm more

Implement yield and send in Scheme

痞子三分冷 提交于 2019-12-17 16:23:12
问题 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 (call/cc (lambda (return) (let ((returner (lambda (value) (call/cc (lambda (next) (return (cons next value))))))) (if (equal? status 'new) (begin (set! status 'running) (current returner)) (current (cons value returner))) (set! status 'dead)))))) (if (pair? continuation

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

两盒软妹~` 提交于 2019-12-10 17:33:47
问题 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, [Symbol.toStringTag]: type, [Symbol("args")]: args}); return cons(f); }; const Cont = structure("Cont") (Cont => f => Cont(f)); const runCont = tf => k => tf.runCont(k); const reset = tf => of(tf.runCont(id)); const shift = f => Cont(k => f(k).runCont(id))

Use MonadRef to implement MonadCont

淺唱寂寞╮ 提交于 2019-12-04 14:55:43
问题 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 :: (forall r.(a -> m r) -> m r) -> m a reset :: m a -> m a and then find an instance that makes sense. In this paper the author claimed that we can implement MonadFix on top of ContT r m providing that m implemented MonadFix and MonadRef . But I think if we do

Use MonadRef to implement MonadCont

拥有回忆 提交于 2019-12-03 09:17:06
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 :: (forall r.(a -> m r) -> m r) -> m a reset :: m a -> m a and then find an instance that makes sense. In this paper the author claimed that we can implement MonadFix on top of ContT r m providing that m implemented MonadFix and MonadRef . But I think if we do have a MonadRef we can actually implement callCC' above like the following: --satisfy law: mzero >>= f ==

What exactly is a “continuation prompt?”

北慕城南 提交于 2019-11-29 20:11:56
I'm trying to decipher the documentation call-with-continuation-prompt Applies proc to the given arg s with the current continuation extended by a prompt. The prompt is tagged by prompt-tag , which must be a result from either default-continuation-prompt-tag (the default) or make-continuation-prompt-tag . The result of proc is the result of the call-with-continuation-prompt call. I understand the part where it says "Applies proc to the given arg s with the current continuation" and then it's just gibberish from there. What does it even mean for a continuation to be "extended," and how does a

What exactly is a “continuation prompt?”

别说谁变了你拦得住时间么 提交于 2019-11-28 16:02:16
问题 I'm trying to decipher the documentation call-with-continuation-prompt Applies proc to the given arg s with the current continuation extended by a prompt. The prompt is tagged by prompt-tag , which must be a result from either default-continuation-prompt-tag (the default) or make-continuation-prompt-tag . The result of proc is the result of the call-with-continuation-prompt call. I understand the part where it says "Applies proc to the given arg s with the current continuation" and then it's

Implement yield and send in Scheme

扶醉桌前 提交于 2019-11-27 23:19:47
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 (call/cc (lambda (return) (let ((returner (lambda (value) (call/cc (lambda (next) (return (cons next value))))))) (if (equal? status 'new) (begin (set! status 'running) (current returner)) (current (cons value returner))) (set! status 'dead)))))) (if (pair? continuation-and-value) (begin (set! current (car continuation-and-value)) (cdr continuation-and-value)) continuation

What are Scala continuations and why use them?

天涯浪子 提交于 2019-11-27 05:51:33
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 that it's good for asynchronous I/O, but I haven't been able to find out why. Some of the more popular resources on the subject are these: Delimited continuations and Scala Goto in Scala A Taste of 2.8: Continuations Delimited Continuations Explained (in Scala) And this question on Stack Overflow: What are the biggest differences between Scala 2.8