In functional programming, what does cps (continuation-passingstyle) mean?

Source: Internet
Author: User
Is there an example that is not based on lisp or c ++, preferably python or lamdbaexpression. Is there an example that is not based on lisp or c ++, preferably python or lamdba expression.

Reply content:

The CPS wraps the code to be executed after the function is called through the closure and calls the function to be executed as a function parameter.

Continuation Passing Style Revisited Part Five: CPS and AsynchronyThe CPS transformation is essentially to pass in another function when calling a function (therefore, the language must support high-level functions and closures). The called function does not return the result to the caller, instead, return the result to the function passed in through the parameter.

I don't know whether the concept is implemented in other languages or by different names.

Here is an example of scheme: call/cc probingAnswer the question from another perspective.
Lambda calculus with callcc can be homogeneous to the classical logic by Curry-Howard, while normal calculus can only be homogeneous to the intuition logic. However, the formal logic has a Gilvenko theorem, which claims:

For any proposition and premise, if and only if it is in the intuition logic in the classical logic

After proving this theorem, Godel (yes, the one that proves that there are uncertain propositions) and gen CEN (inventor of natural deduction and successive calculus) invented the double negative transformation, the rule is also called the Godel-kenen Transformation:


Note that any proposition of the Godel-gencen transformation is equivalent to the original proposition classic, but not intuition equivalent (intuition logic itself denies), but according to the Gilvenko theorem, if the double-negative proposition can be proved true in the intuitive logic system, it must be true in the classic logic system, and vice versa.
Then, according to Curry-Howard's homogeneous structure, the type assignment under the calculation can be obtained through the Godel-kenen transformation to assign a computing type:, the expression (homogeneous in the proof process) the process is the CPS transformation. If we directly copy the type in the Godel-kenen transformation, we have the following results:

  1. Atom

  2. Call

  3. Abstraction

  4. Call/cc Operator

It can be proved that the CPS transformation does not change the semantics.
Of course, this version of CPS is very lengthy, and all those seen on the market have made the Protocol directly after the transformation and deleted a bunch of Redex.

The above once again demonstrates how closely logical and programming are linked. .

This is a simple function compute output:

  static int Times3(int x)    {        return x * 3;    }   Console.WriteLine(Times3(5));

(The answer is copied from http://www.cs.indiana.edu/cgi-pub/lkuper/c311/_media/cps-notes.scm)
Define the following four functions (two functions are enough to maintain consistency with the original answer)

def f(var0):    passdef g(var0, var1):    return passdef h(var0):    return passdef j(var0):    return pass

In fact

Fuckee FindFuckee () {return kula;} void Fuck (Fuckee fuckee, int count) {for (int I = 0; I
 
  

The answer to logic can be supplemented by logic... @ Belleve is too abstract, and people without logic background cannot understand it,
On Quora, I saw a well-written answer, which may be explained from the logic point of view as a supplement to @ Belleve's answer:
What is continuation-passing style in functional programming?

In functional programming, what is the meaning of cps (continuation-passing style? For more information, see the PHP Chinese website (www.php1.cn )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.