continuations

Using Cont to acquire values from the future and the past

旧时模样 提交于 2019-12-02 21:36:00
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)) | Halt However, it's tricky to parse a textual representation of a brainfuck program into this data type. The problem arises with trying to correctly parse square brackets, because there is some knot-tying to do so that the final Instruction inside a loop links to the loop's Control again. A bit more preliminary information. See this version on the github repo for all the details. type

Precise flow control in Haskell

假装没事ソ 提交于 2019-12-02 21:24:03
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 could be accessed anywhere in the code (you can think of it like about State monad, but a little funnier). The funny thing about it, is that we can use timeShift operation on results, affecting the time corresponding operations would see. An example would be best to explain this situation. Lets use following dataflow diagram: -- timeShift(*2) -- -- /

C# first class continuation via C++ interop or some other way?

邮差的信 提交于 2019-12-02 20:12:20
We have a very high performance multitasking, near real-time C# application. This performance was achieved primarily by implementing cooperative multitasking in-house with a home grown scheduler. This is often called micro-threads. In this system all the tasks communicate with other tasks via queues. The specific problem that we have seems to only be solvable via first class continuations which C# does not support. Specifically the problem arises in 2 cases dealing with queues. Whenever any particular task performs some work before placing an item on a queue. What if the queue is full?

Why continuation passing style

て烟熏妆下的殇ゞ 提交于 2019-12-02 18:08:04
In The Scheme Programming Language by Kent Dybvig (4th edition) section 3.4 , he describes very clearly what continuation passing style is. For the why he gives two reasons: pass more than one result to its continuation, because the procedure that implements the continuation can take any number of arguments. CPS also allows a procedure to take separate continuations ..., which may accept different numbers of arguments. Since the first reason can also be done using the values procedure and the second using case-lambda , I'm not clear the advantages of using continuation passing style. Could

scheme continuation inside a for-each

二次信任 提交于 2019-12-02 02:43:34
问题 I'm currently studying Scheme for a course at my university, while looking at some exercises I got stuck on this particular one. Professor has yet to answer my previous mails therefore I have more chances to receive an answer here faster. Given this code (define (list-iter-cc lst) (call/cc (lambda (return) (for-each (lambda (x) (call/cc (lambda (next-step) (return (cons x next-step))))) lst) 'end))) I have to use it to write the iter macro whose syntax is (iter <a variable symbol> in <a list>

scheme continuation inside a for-each

空扰寡人 提交于 2019-12-02 02:11:56
I'm currently studying Scheme for a course at my university, while looking at some exercises I got stuck on this particular one. Professor has yet to answer my previous mails therefore I have more chances to receive an answer here faster. Given this code (define (list-iter-cc lst) (call/cc (lambda (return) (for-each (lambda (x) (call/cc (lambda (next-step) (return (cons x next-step))))) lst) 'end))) I have to use it to write the iter macro whose syntax is (iter <a variable symbol> in <a list> <code>) example: (iter x in '(1 2 3) (display x) (newline)) Since I couldn't understand list-iter-cc i

boost::future and continuations - value set, but future still blocks

霸气de小男生 提交于 2019-12-02 02:08:52
I am trying to make the following continuation work - but f.get() blocks. Whats wrong? #include <iostream> #define BOOST_THREAD_PROVIDES_FUTURE #define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION #include <boost/thread/future.hpp> struct Foo { boost::future<int> start() { return p.get_future(); } void finish() { p.set_value(23); } boost::promise<int> p; }; int main () { Foo foo; foo.start().then([](boost::future<int> f) { std::cout << "done:" << std::endl; std::cout << f.get() << std::endl; }); foo.finish(); } It'll print the "done:" , so the future fires, but it'll then just "hang" on f.get() .

continuations in Scala 2.8.1 and Eclipse

故事扮演 提交于 2019-12-02 00:36:03
问题 How can i start scala (or scalac) with the -P:continuations:enable flag in Eclipse I used import scala.util.continuations._; in my code , and need to enable the plugin. 回答1: Window -> Preferences -> Scala -> Compiler add continuations:enable to P input box 回答2: Window -> Preferences -> Scala -> Compiler -> Standard add continuations:enable to P input box Window -> Preferences -> Scala -> Compiler -> Advanced add lib\continuations.jar to XPlugin Window -> Preferences -> Scala -> Compiler ->

How to adapt trampolines to Continuation Passing Style?

亡梦爱人 提交于 2019-12-01 18:17:12
Here is a naive implementation of a right fold: const foldr = f => acc => ([x, ...xs]) => x === undefined ? acc : f(x) (foldkr(f) (acc) (xs)); This is non-tail recursion and hence we cannot apply a trampoline. One approach would be to make the algorithm iterative and use a stack to mimick the function call stack. Another approch would be to transform the recursion into CPS: const Cont = k => ({runCont: k}); const foldkr = f => acc => ([x, ...xs]) => Cont(k => x === undefined ? k(acc) : foldkr(f) (acc) (xs) .runCont(acc_ => k(f(x) (acc_)))); This is still naive, because it is insanely slow.

How to adapt trampolines to Continuation Passing Style?

有些话、适合烂在心里 提交于 2019-12-01 17:34:09
问题 Here is a naive implementation of a right fold: const foldr = f => acc => ([x, ...xs]) => x === undefined ? acc : f(x) (foldkr(f) (acc) (xs)); This is non-tail recursion and hence we cannot apply a trampoline. One approach would be to make the algorithm iterative and use a stack to mimick the function call stack. Another approch would be to transform the recursion into CPS: const Cont = k => ({runCont: k}); const foldkr = f => acc => ([x, ...xs]) => Cont(k => x === undefined ? k(acc) : foldkr