Lecture Programming languages (2/e): Chapter 14a - Tucker, Noonan

Functional programming models a computational problem as a collection of mathematical functions, each with an input (domain) and a result (range) spaces. Functions interact and combine with each other using functional composition, conditionals, and recursion. Major functional programming languages are Lisp, Scheme, Haskell, and ML. Functional programming is discussed and illustrated in Chapter 14. | Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis Contents Functions and the Lambda Calculus Scheme Expressions Expression Evaluation Lists Elementary Values Control Flow Defining Functions Let Expressions Example: Semantics of Clite Example: Symbolic Differentiation Example: Eight Queens Haskell Overview of Functional Languages They emerged in the 1960’s with Lisp Functional programming mirrors mathematical functions: domain = input, range = output Variables are mathematical symbols: not associated with memory locations. Pure functional programming is state-free: no assignment Referential transparency: a function’s result depends only upon the values of its parameters. Functions and the Lambda Calculus The function Square has R (the reals) as domain and range. Square : R R Square(n) = n2 A function is total if it is defined for all values of its domain. Otherwise, it is partial. ., Square is total. A lambda expression is a particular way to define a function: LambdaExpression variable | ( M N) | ( variable . M ) M LambdaExpression N LambdaExpression ., ( x . x2 ) represents the Square function. Properties of Lambda Expressions In ( x . M), x is bound. Other variables in M are free. A substitution of N for all occurrences of a variable x in M is written M[x N]. Examples: A beta reduction (( x . M)N) of the lambda expression ( x . M) is a substitution of all bound occurrences of x in M by N. ., (( x . x2)5) = 52 Function Evaluation In pure lambda calculus, expressions like (( x . x2)5) = 52 are uninterpreted. In a functional language, (( x . x2)5) is interpreted normally (25). Lazy evaluation = delaying argument evaluation in a function call until the argument is needed. Advantage: flexibility . | Programming Languages 2nd edition Tucker and Noonan Chapter 14 Functional Programming It is better to have 100 functions operate one one data structure, than 10 functions on 10 data structures. A. Perlis Contents Functions and the Lambda Calculus Scheme Expressions Expression Evaluation Lists Elementary Values Control Flow Defining Functions Let Expressions Example: Semantics of Clite Example: Symbolic Differentiation Example: Eight Queens Haskell Overview of Functional Languages They emerged in the 1960’s with Lisp Functional programming mirrors mathematical functions: domain = input, range = output Variables are mathematical symbols: not associated with memory locations. Pure functional programming is state-free: no assignment Referential transparency: a function’s result depends only upon the values of its parameters. Functions and the Lambda Calculus The function Square has R (the reals) as

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
76    741    3    01-05-2024
5    74    1    01-05-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.