The root-λ expression of functional programming (lambda expression)

Source: Internet
Author: User
Tags mathematical functions

Learn the big map/aerial view of functional programming and give the scheme code before you have mastered the various language details of scheme. This means that we do not need to read the source code, but the introduction here as a follow-up study of the large map, so that they know where the body;


At the beginning of 1930s, Alonzo Church,1903-1995 , a Arenzo Chuchi at Princeton University, developed a new form system (formal system), lambda Operations/calculus (Λ-calculus, lambda calculus , Lambda is the Greek alphabet λ).

The core of the lambda operation is the lambda expression , which forms the function definition, the function application and the recursive system. When a lambda expression is used to define language elements such as Boolean, numeric, and various basic operators, it is possible to form a programming language , so the lambda operation is a common ancestor of functional programming languages, typically represented by Lisp (Scheme), ML, Haskell, Erlang, and so on.

Since any computable function can be expressed and evaluated using the λ operation, it is equivalent to the Turing. 0.1.1λ-expression

Ordinary mathematical functions such as f (x) =x+1, function is to give its parameter x plus 1. In order to represent the mathematical function as a commonly used expression in a computer, you can change the wording:

λx. (x+1), read into"for parameter x,x+1"(assuming that operator + is already defined). Church chose λ, so various related calculations are called λ calculus.

Various programming languages, as well as the introduction of lambda expressions. For example:

C # language: (x) =>{return x+1;}

Java language: (x)->{return x+1;}

Scheme language:(Lambda (x) (+ x 1))

Definition of 1.λ expression

The lambda expression is extremely concise, consisting of a variable, two abstract symbols λ and. (that is, dots), and parentheses (). The recursive definition of a valid lambda expression is as follows:

    • The variable x is a lambda expression.
    • Function Abstraction: W is the lambda expression with the argument variable x, then λx. W is the lambda expression. This expression gives the definition of a function: W is the function body, and the parameter is the variable x.
      Λx. (x+1)
      Λx. Λy. (x+y);;; Represents Λx. (Λy. (X+y))
    • Function application: With f (x) =x+1, you naturally need to calculate F (2), which is to evaluate the function as an (actual) parameter. A, B is a lambda expression, then (a B) is also a lambda expression, which means that the argument B is brought into function A.

In general, programming languages provide built-in basic functions, such as various operators. The application of the operator "is a" function application, from the perspective of the recursive definition of the lambda expression, the "function application" rule can have a more straightforward rule:

    • An expression consisting of an operator and a lambda expression is a lambda expression. such as X+1

Here are some examples of lambda expressions:

(simplest) x, Y,

(function Abstraction) λx.x, λx.y,

(function applied) λx.x y, (x y), λx. (x y) ...

characteristics of 2.λ Expressions

From the definition of the lambda expression, it can be inferred from its two characteristics:

    • anonymous function. a mathematical function such as an F (x) =x+1 or λ expression such as λx. (X+1), which describes a computational process; naming the function is a programmer's business.
    • Each function has only one input parameter, such as Λn. Λm.λf.λx. ((n f) (+ + M)). Programming-time functions can have a list of arguments, and the logic home Haskell Curry proves that a function that has multiple parameters can be converted into successive invocations of multiple functions with only one parameter, a conversion process called a currying/currying of functions that have multiple parameters.
3. Through church number, familiar with the α-transform and β simplification of the lambda calculus.

The root-λ expression of functional programming (lambda expression)

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.