PPL Unit-5
PPL Unit-5
1) lambda calculus
Lambda Calculus
Lambda calculus (λ-calculus), is the world's smallest
programming language. Despite not having numbers, strings,
booleans, or any non-function datatype, lambda calculus can be used
to represent any Turing Machine!
Lambda calculus is composed of 3 elements: variables, functions,
and applications.
Name Syntax Example Explanation
Evaluation:
Evaluation is done via β-Reduction, which is essentially lexically-
scoped substitution.
When evaluating the expression (λx.x)a, we replace all
occurrences of "x" in the function's body with "a".
• (λx.x)a evaluates to: a
Note: Although lambda calculus traditionally supports only single
parameter functions, we can create multi-parameter functions using
a technique called currying.
• (λx.λy.λz.xyz) is equivalent to f(x, y, z) = ((x y) z)
Numbers:
0 = λf.λx.x
1 = λf.λx.f x
2 = λf.λx.f(f x)
3 = λf.λx.f(f(f x))
2) Functional programming languages
Functional programming is a declarative programming
paradigm style where one applies pure functions in sequence to
solve complex problems.
o Bugs-Free code:
o Efficient Programming Language:
o Efficiency-
o Supports Nested Functions
Note: Functional programming does not have any state, so all the
time, there is a need to create new objects to perform the actions.
That's why functional programming needs a large memory space.
Example :
friends(raju, mahesh).
singer(sonu).
odd_number(5).
Explanation :
These facts can be interpreted as :
raju and mahesh are friends.
sonu is a singer.
5 is an odd number.
Running queries :
Query 1 : ?- singer(sonu).
Output : Yes.
Explanation : As our knowledge base contains
the above fact, so output was 'Yes', otherwise
it would have been 'No'.
Query 2 : ?- odd_number(7).
Output : No.
Explanation : As our knowledge base does not
contain the above fact, so output was 'No'.
Key Features :
1. Unification : The basic idea is, can the given terms be made to
represent the same structure.
2. Backtracking : When a task fails, prolog traces backwards and tries
to satisfy previous task.
3. Recursion : Recursion is the basis for any search in program.
5) ML
➢ A static-scoped functional language with syntax that is closer to
Pascal than to LISP
➢ Uses type declarations, but also does type inferencing to
determine the types of undeclared variables
➢ It is strongly typed (whereas Scheme is essentially typeless) and
has no type coercions
➢ Includes exception handling and a module facility for
implementing abstract data types
➢ Includes lists and list operations
6) Logic Programming:
Logic programming expresses and manipulates logic-based
relationships and rules in a declarative manner.
Logic programs, driven solely by data, utilize logical statements
known as predicates, which are either facts or rules.
Major logic programming language families include Prolog,
Answer Set Programming (ASP) and Datalog.
Functional Programming Logical Programming