continuations

Is there a continuation-like type for wrapping an execution block, like (Ctx => R) => R or (=> R) => R?

穿精又带淫゛_ 提交于 2019-12-10 14:35:34
问题 I'm looking for such a type that would allow me to represent a context, in which a piece of code is run. For example: def withinContext[R]: ((=> R) => R) = (inner) => { initializeSomeResource() try { inner } finally { releaseTheResource() } } which then I can use simply as withinContext { ... } Or, if the inner block of code needs some information from the context, generalize it as def withinContext[R]: ((Ctx => R) => R) = ... Their use cases roughly correspond to Haskell's bracket_ and

What are “Jetty 6 Continuations” and how do they compare to the continuations found in programming languages?

扶醉桌前 提交于 2019-12-10 11:26:04
问题 I'm looking for an answer that describes a "continuation" mechanism in a web server vs. a programming language. My understanding is that using continuations, it is trivial to have a "digits of pi" producer communicate with a "digits of pi" consumer, without explicit threading. I've heard very good things about Jetty continuations. I am curious what others think. I may have already found my answer, but I'm asking the question here anyway - for the record. 回答1: how do they compare to the

Play's continuations holding http threads

不想你离开。 提交于 2019-12-09 17:25:20
问题 We have implemented a feature in our web app that updates the GUI in response to new events in the server by using Play's continuations, just like a chat app. After running it for some time in production we started to experience server hangs, more specifically the http connector of our Glassfish server stopped accepting new requests. A thread dump shows us that all http threads from the http thread pool are waiting for Play Promises to be invoked. Our thread pool has 5 threads (the default

Is there a way to chain functions like withCString?

别说谁变了你拦得住时间么 提交于 2019-12-09 14:50:06
问题 Is there a way to chain functions like withCString ? By that I mean any function that looks something like f :: Foo -> (CFoo -> IO a) -> IO a . For example, lets say there is a function cFunc :: CString -> CFoo -> CBar -> IO () Usualy, I would do something like: haskellFunc string foo bar = withCString string $ \ cString -> withCFoo foo $ \ cFoo -> withCBar bar $ \ cBar -> cFunc cString cFoo cBar But i would like to do something like: haskellFunc = (withCString |.| withCFoo |.| withCBar)

Scala continuation and exception handling

此生再无相见时 提交于 2019-12-09 10:11:52
问题 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? 回答1: Here is one of the possible ways of implementing resumable error handling: import java.io.File import java.lang.IllegalStateException import scala.util.continuations._ // how it works ctry { println("start") val operationResult = someOperation(new File(

Equational reasoning with tying the knot

◇◆丶佛笑我妖孽 提交于 2019-12-08 17:28:16
问题 I'm trying to wrap my head around Cont and callCC, by reducing this function: s0 = (flip runContT) return $ do (k, n) <- callCC $ \k -> let f x = k (f, x) in return (f, 0) lift $ print n if n < 3 then k (n+1) >> return () else return () I've managed to reach this point: s21 = runContT (let f x = ContT $ \_ -> cc (f, x) in ContT ($(f,0))) cc where cc = (\(k,n) -> let iff = if n < 3 then k (n+1) else ContT ($()) in print n >> runContT iff (\_ -> return ())) And at this point i have no idea what

What do “continuations” mean in functional programming?(Specfically SML)

≯℡__Kan透↙ 提交于 2019-12-07 09:18:31
问题 I have read a lot about continuations and a very common definition I saw is, it returns the control state. I am taking a functional programming course taught in SML. Our professor defined continuations to be: "What keeps track of what we still have to do" ; "Gives us control of the call stack" A lot of his examples revolve around trees. Before this chapter, we did tail recursion. I understand that tail recursion lets go of the stack to hold the recursively called functions by having an

Use Spring Web Flow without state on the server

梦想的初衷 提交于 2019-12-07 06:47:41
问题 I'm reading the Spring Web Flow chapter in the book Pro Spring MVC. Unfortunately there's no explicit information, where the state during a flow execution is persisted. I assume it is saved in the JVM Heap and associated with the session. Now HTTP is a stateless protocol (REST...) and I'd like to use Spring Web Flow without saving state on the server (besides the one and only state that a session might be authenticated). One strategy is to send all parameters of the entire flow with every

Letrec and reentrant continuations

╄→гoц情女王★ 提交于 2019-12-07 05:31:59
问题 I have been told that the following expression is intended to evaluate to 0, but that many implementations of Scheme evaluate it as 1: (let ((cont #f)) (letrec ((x (call-with-current-continuation (lambda (c) (set! cont c) 0))) (y (call-with-current-continuation (lambda (c) (set! cont c) 0)))) (if cont (let ((c cont)) (set! cont #f) (set! x 1) (set! y 1) (c 0)) (+ x y)))) I must admit that I cannot tell where even to start with this. I understand the basics of continuations and call/cc , but

Different kinds of continuations in Racket

﹥>﹥吖頭↗ 提交于 2019-12-07 04:45:06
问题 Can someone give a relatively simple example of the differences in Racket between call-with-composable-continuation and call-with-current-continuation . I've worked through the examples in the Racket Guide 10.3 of call-with-composable-continuation , and the examples of call-with-current-continuation in The Scheme Programming language section 3.3 but I'm not clear on the difference. Could someone give an example where they would give different results in the same context. 回答1: A very thorough