Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When and how to use continuation passing style

Tags:

c#

I have been reading about the continuation passing style programming technique (C# 3.0 implementation).

Why/when it would be useful to use this technique?

How can I implement this to get those really long chains? Is this the same as currying (which yields some better search results in google)?

Thanks

like image 808
GurdeepS Avatar asked Aug 20 '09 22:08

GurdeepS


People also ask

What is the benefit of continuation passing style?

Continuation passing style makes the control flow of programs more explicit as every procedure has the power to change the execution of the remainder of the program, contrast this to the traditional model in which procedures have no control over the behavior of the program once they return to their caller.

What does continuation passing style give you that tail recursion does not?

Continuation-Passing-Style, Tail Recursion, and Efficiency is not tail recursive, because the recursive call fact(n-1) is not the last thing the function does before returning. Instead, the function waits for the result of the recursive call, then multiples that by the value of n.

What is the function of continuation?

A continuation is a callback function k that represents the current state of the program's execution. More precisely, the continuation k is a function of one argument, namely the value that has been computed so far, that returns the final value of the computation after the rest of the program has run to completion.

What is continuation programming?

A continuation implements (reifies) the program control state, i.e. the continuation is a data structure that represents the computational process at a given point in the process's execution; the created data structure can be accessed by the programming language, instead of being hidden in the runtime environment.


1 Answers

An excellent write-up on CPS in C# context was made by Wes Dyer. I don't think I could possibly add anything meaningful to that. If some specific things are unclear there, go ahead and ask about them.

like image 96
Pavel Minaev Avatar answered Oct 01 '22 02:10

Pavel Minaev