Functional Programming

Functional Programming

  • Programming paradigm that treats computation as the evaluation of mathematical functions.
  • Has roots in lambda calculus, a formal system developed in the 1930s to investigate function definition, function application, and recursion.
  • Declarative programming paradigm, which means programming is done with expressions



procedural vs Functional Language

Procedural Programming


  • Have fixed execution order.
  • Example : Swap values  of two varriables.

T = X ;
X = Y ;
Y= T; 


Procedural

  • Sum of N elements

 I := 0 ;
SUM := 0 ;
WHILE I < N DO
BEGIN
I := I + 1 ;
SUM := SUM + A[I]
END

Functional


 FUNCTION SUM(A:ARRAY [1..N] OF INTEGER; I,N:INTEGER):INTEGER;
BEGIN
IF I > N THEN
SUM := 0
ELSE
SUM := A[I] + SUM(A,I+1,N)
END

in C#
 int sum = Enumerable.Range(0, 150).Where(i => i % 5 != 0).Sum();

References


Functional Programming

By Torry Harris Business Solutions