Programming Language Master's Degree by Slidesgo
Programming Language Master's Degree by Slidesgo
Programming
Language
Table of contents
Functional
01 Programming 02 Lambda Calculus
03 Reduction
04 Recursion
01
Functional
Programming
“In computer science, functional
programming is a programming
paradigm where programs are constructed
by applying and composing functions”
Lazy Evaluation
Functional programming supports Lazy
Functional Constructs like Lazy Lists, Lazy
Maps, etc.
Syntax
returnType functionName (type1 argument1,
type2 argument2, . . . )
{
// function body
}
Example
sum(x, y) // sum is function
taking x and y as
arguments return
x + y // sum is returning sum
of x and y without changing
them
02
Lambda
Calculus
Lambda calculus (also written as λ-calculus) is
a formal system in mathematical logic for
expressing computation based on function
abstraction and application using variable
binding and substitution.
• E :: = x (variables)
• | E1 E2 (function application)
• | λx.E (function creation)
(+ (* 5 6) (* 8 3))
For example −
(+ (* 5 6) (* 8 3))
(+ 30 (* 8 3))
(+ 30 24)
= 54
03
Reduction
The meaning of lambda
expressions is defined by
how expressions can be
reduced.
Types of Reduction
α-conversion
changing bound variables
η-reduction
which captures a notion of
extensionality
β-reduction
applying functions to their
arguments
Reduction strategies
• Normal order
The leftmost, outermost redex is always reduced first. That is,
whenever possible the arguments are substituted into the body of
an abstraction before the arguments are reduced.
• Applicative order
The leftmost, innermost redex is always reduced first. Intuitively
this means a function's arguments are always reduced before the
function itself. Applicative order always attempts to apply
functions to normal forms, even when this is not possible.
• Full β-reductions
Any redex can be reduced at any time. This means essentially the
lack of any particular reduction strategy—with regard to
reducibility, "all bets are off".
04
Recursion
Recursive functions repeatedly
call themselves, until it reaches
the base case.
fib(n)
if (n <= 1)
return 1;
Else
return fib(n - 1) + fib(n - 2);
Consider the factorial function F(n) recursively defined by
F(n) = 1, if n = 0; else n × F(n − 1)
In the lambda expression which is to represent this function, a parameter (typically the first
one) will be assumed to receive the lambda expression itself as its value, so that
calling it – applying it to an argument – will amount to recursion. Thus to achieve
recursion, the intended-as-self-referencing argument (called r here) must always be
passed to itself within the function body, at a call point: