scala,f#,functional-programming,tail-recursion,continuation-passing
The second call to go on line 4 is not in tail position, it is wrapped inside an anonymous function. (It is in tail position for that function, but not for go itself.) For continuation passing style you need Proper Tail Calls, which Scala unfortunately doesn't have. (In order to...
javascript,continuation-passing
Continuation passing style is really simple. For example, suppose you have the following functions which you want to convert to CPS: function f(x) { return x + 1; } function g(x) { return x * 2; } function h() { return 3; } alert(f(g(h()))); Written in CPS: function f(k) {...
haskell,continuations,continuation-passing
The translation is fairly mechanical. Keep in mind that in the continuation monad, return feeds the value into the continuation. evalStmt :: Statement -> Cont Value Value evalStmt (Expr val) = let res = Value val in return res evalStmt (Block stmts) = evalBlock stmts evalStmt (Return val) = cont...
scheme,continuations,continuation-passing,callcc
With Continuation Passing Style (without call/cc) It may be easier to understand this example if you implement a version that uses explicit continuation passing style rather than call/cc first. In this case, let's start with a continuation passing version of map: (define (kmap fn list k) (if (null? list) (k...
haskell,monads,continuation-passing
You could ask the same question of any Monad. Off the top of my head, I can think of three advantages: You get access to the huge collection of functions that are designed to work with Monads. You can use do-notation. You can stack up monad transformers to create something...