167 questions
0 votes
2 answers
105 views
SML Circularity error when writing in Continuation-Passing Style
I'm trying to implement iteration using continuations fun stringChars string = let val len = size string fun nextChar index kEndOfString kReadChar = if len = index then ...
0 votes
1 answer
72 views
Have I traced the continuations right?
I am learning the concept of continuations. I thought a good idea was to trace the typical factorial code when written with the continuation form. I want to know if my understanding is correct. Code: ...
0 votes
0 answers
50 views
Order of nester requestAnimation frame seems incorrect
What I want to achieve is 2 loops (anim1 and anim2), while anim2 contains nested loop internalAnim2 The output of the following code should be: anim1 - 4 times (= a1Max) and 5 times (=a2Max) those 3 ...
0 votes
1 answer
211 views
How to write fold_left in CPS?
Even though it's already tail-recursive, It's still interesting to see a CPS version of it. Here's the standart fold_left: let rec myFoldLeft f acc list = match list with | [] -> acc | h :: ...
0 votes
1 answer
143 views
Antlr adding additional parameters to visit methods, accommodations for continuation passing style
I am trying to do continuation passing style for a simple programming language made with antlr. Typically you would have an eval procedure that takes as arguments the expression to be evaluated as ...
2 votes
1 answer
587 views
call/cc example in JavaScript
Now that ES6 supports Proper Tail Call, and since according to Wikipedia, "In any language which supports closures and proper tail calls, it is possible to write programs in continuation-passing ...
2 votes
1 answer
237 views
How Kotlin coroutine internals decide should function be suspended or result can be returned immediately?
As I understand suspend function transforms to function with additional Continuation parameter and when block from suspendCoroutineUninterceptedOrReturn returning COROUTINE_SUSPENDED value - suspend ...
2 votes
1 answer
89 views
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 (...
0 votes
2 answers
106 views
Why would wrapping recursive function in promise improves the performance?
I was playing around with recursion and looking at the benchmark of different implementation. function plusOne(xs) { if (xs.length <= 0) return [] return [xs[0], ...plusOne(xs.slice(1))] } ...
0 votes
1 answer
374 views
Continuation Passing Style in Haskell with Binary Tree
I'm just learning CPS and I'm trying to pass the following program to this style mirror Void = Void mirror (Node x left right) = Node x (mirror right) (mirror left) From what I understand I have to ...
3 votes
1 answer
504 views
Tail recursion elimination on conditional types doesn't work
In TS 4.5 tail call optimization was added for recursive generics. The following snippet computes Fibonacci numbers (in unary) up to F12, but for F13 it fails with the usual "Type instantiation ...
0 votes
2 answers
606 views
What are the continuation passing style conversion rules?
I am trying to understand continuation passing style conversion. I am trying to build a Scheme to C compiler and I want to use continuation passing style. Whether or not continuation passing style is ...
0 votes
1 answer
39 views
Relationship between a higher order programming language, and contuation passing style?
Suppose I have a higher order language defined with the (rough) BNF (using Lisp notation): c ::= constants v ::= variables e ::= c | v | (if e e e) | (e e_1 e_2 ... e_n) | (fn [v_1 v_2 ... v_n] e) In ...
1 vote
1 answer
221 views
Why does converting the factorial function to iterative form by defunctionalizing the continuation give such a bad result?
I'm trying the "defunctionalize the continuation" technique on some recursive functions, to see if I can get a good iterative version to pop out. Following along with The Best Refactoring ...
0 votes
2 answers
170 views
F# continuation recursion bug
I'm having an issue with a recursive function that runs into a stack overflow on larger data sets so I've attempted to rewrite the function to use continuous recursion but to say I'm new to this would ...