0% found this document useful (0 votes)
87 views10 pages

Functional Programming Paradigm: Courses

The document discusses the functional programming paradigm. It defines functional programming as a declarative style that focuses on what to solve rather than how to solve. It is based on lambda calculus and uses pure functions, recursion, referential transparency, and immutable variables. Some languages that support functional programming are Haskell, JavaScript, Python, Scala, Erlang, Lisp, ML, Clojure, OCaml, Common Lisp, and Racket. Advantages include easier debugging and support for concurrency, while disadvantages include potentially reduced readability and performance.

Uploaded by

felixhahn721
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views10 pages

Functional Programming Paradigm: Courses

The document discusses the functional programming paradigm. It defines functional programming as a declarative style that focuses on what to solve rather than how to solve. It is based on lambda calculus and uses pure functions, recursion, referential transparency, and immutable variables. Some languages that support functional programming are Haskell, JavaScript, Python, Scala, Erlang, Lisp, ML, Clojure, OCaml, Common Lisp, and Racket. Advantages include easier debugging and support for concurrency, while disadvantages include potentially reduced readability and performance.

Uploaded by

felixhahn721
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks

90% Refund @Courses Trending Now Data Structures & Algorithms Foundational Courses Data Science

Functional Programming Paradigm


Read Courses

Introduction
Functional programming is a programming paradigm in which we try to bind
everything in pure mathematical functions style. It is a declarative type of
programming style. Its main focus is on “what to solve” in contrast to an
imperative style where the main focus is “how to solve”. It uses expressions
instead of statements. An expression is evaluated to produce a value
whereas a statement is executed to assign variables. Those functions have
some special features discussed below.

Functional Programming is based on Lambda Calculus:


Lambda calculus is a framework developed by Alonzo Church to study
computations with functions. It can be called as the smallest programming
language in the world. It gives the definition of what is computable.
Anything that can be computed by lambda calculus is computable. It is
equivalent to Turing machine in its ability to compute. It provides a
theoretical framework for describing functions and their evaluation. It forms
the basis of almost all current functional programming languages.
Fact: Alan Turing was a student of Alonzo Church who created Turing
machine which laid the foundation of imperative programming style.

Programming Languages that support functional programming: Haskell,


JavaScript, Python, Scala, Erlang, Lisp, ML, Clojure, OCaml, Common Lisp,
Racket.

Concepts of functional programming:

Pure functions
Recursion
Referential transparency
Functions are First-Class and can be Higher-Order
https://www.geeksforgeeks.org/functional-programming-paradigm/ 1/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks

Variables are Immutable

Pure functions: These functions have two main properties. First, they
always produce the same output for same arguments irrespective of
anything else.
Secondly, they have no side-effects i.e. they do not modify any arguments or
local/global variables or input/output streams.
Later property is called immutability. The pure function’s only result is the
value it returns. They are deterministic.
Programs done using functional programming are easy to debug because
pure functions have no side effects or hidden I/O. Pure functions also make it
easier to write parallel/concurrent applications. When the code is written in
this style, a smart compiler can do many things – it can parallelize the
instructions, wait to evaluate results when needing them, and memorize the
results since the results never change as long as the input doesn’t change.
example of the pure function:

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

Recursion: There are no “for” or “while” loop in functional languages.


Iteration in functional languages is implemented through recursion.
Recursive functions repeatedly call themselves, until it reaches the base
case.
example of the recursive function:

fib(n)
if (n <= 1)
return 1;
else
return fib(n - 1) + fib(n - 2);

Referential transparency: In functional programs variables once defined do


not change their value throughout the program. Functional programs do not
have assignment statements. If we have to store some value, we define new
variables instead. This eliminates any chances of side effects because any

https://www.geeksforgeeks.org/functional-programming-paradigm/ 2/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks

variable can be replaced with its actual value at any point of execution. State
of any variable is constant at any instant.

Example:

x = x + 1 // this changes the value assigned to the variable x.


// So the expression is not referentially transparent.

Functions are First-Class and can be Higher-Order: First-class functions


are treated as first-class variable. The first class variables can be passed to
functions as parameter, can be returned from functions or stored in data
structures. Higher order functions are the functions that take other functions
as arguments and they can also return functions.

Example:

show_output(f) // function show_output is declared taking


argument f
// which are another function
f(); // calling passed function

print_gfg() // declaring another function


print("hello gfg");

show_output(print_gfg) // passing function in another function

Variables are Immutable: In functional programming, we can’t modify a


variable after it’s been initialized. We can create new variables – but we
https://www.geeksforgeeks.org/functional-programming-paradigm/ 3/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks

can’t modify existing variables, and this really helps to maintain state
throughout the runtime of a program. Once we create a variable and set its
value, we can have full confidence knowing that the value of that variable
will never change.

Advantages and Disadvantages of Functional programming

Advantages:

1. Pure functions are easier to understand because they don’t change any
states and depend only on the input given to them. Whatever output they
produce is the return value they give. Their function signature gives all
the information about them i.e. their return type and their arguments.
2. The ability of functional programming languages to treat functions as
values and pass them to functions as parameters make the code more
readable and easily understandable.
3. Testing and debugging is easier. Since pure functions take only
arguments and produce output, they don’t produce any changes don’t
take input or produce some hidden output. They use immutable values, so
it becomes easier to check some problems in programs written uses pure
functions.
4. It is used to implement concurrency/parallelism because pure functions
don’t change variables or any other data outside of it.
5. It adopts lazy evaluation which avoids repeated evaluation because the
value is evaluated and stored only when it is needed.

Disadvantages:

1. Sometimes writing pure functions can reduce the readability of code.


2. Writing programs in recursive style instead of using loops can be bit
intimidating.
3. Writing pure functions are easy but combining them with the rest of the
application and I/O operations is a difficult task.
4. Immutable values and recursion can lead to decrease in performance.

Applications:

It is used in mathematical computations.


It is needed where concurrency or parallelism is required.

https://www.geeksforgeeks.org/functional-programming-paradigm/ 4/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks

Fact: Whatsapp needs only 50 engineers for its 900M users because Erlang
is used to implement its concurrency needs. Facebook uses Haskell in its
anti-spam system.

Whether you're preparing for your first job interview or aiming to upskill in
this ever-evolving tech landscape, GeeksforGeeks Courses are your key to
success. We provide top-quality content at affordable prices, all geared
towards accelerating your growth in a time-bound manner. Join the millions
we've already empowered, and we're here to do the same for you. Don't
miss out - check it out now!

Looking for a place to share your ideas, learn, and connect? Our Community
portal is just the spot! Come join us and see what all the buzz is about!

Last Updated : 28 Jun, 2022

Previous Next

5G Network Architecture Find maximum element of each row in a


matrix

Share your thoughts in the comments Add Your Comment

Similar Reads

https://www.geeksforgeeks.org/functional-programming-paradigm/ 5/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks

Difference between Functional Software paradigm and Software


Programming and Object Oriented Development Life Cycle (SDLC)
Programming

How to prepare for ICFP or


International Conference on Functional Functional Components of a Computer
Programming?

Functional Hazard Functional Modelling in object oriented


analysis and design

Top 10 Functional Testing Tools and Top Programming Languages For


Frameworks in 2024 Competitive Programming

Top 10 Programming Languages of Programming languages one should


2015 learn in 2018

Complete Tutorials
GeeksforGeeks Online Tutorials - FREE! ChatGPT Tutorial: ChatGPT-3.5 Guide
for Beginners

Computer Science and Programming Introduction to Monotonic Stack - Data


For Kids Structure and Algorithm Tutorials

Introduction to Greedy Algorithm - Data


Structures and Algorithm Tutorials

V Vishalxviii

Article Tags : Computer Subject , GBlog , Misc , Technical Scripter


Practice Tags : Misc

Additional Information

https://www.geeksforgeeks.org/functional-programming-paradigm/ 6/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks

A-143, 9th Floor, Sovereign Corporate


Tower, Sector-136, Noida, Uttar Pradesh -
201305

Company Explore
About Us Job-A-Thon Hiring Challenge
Legal Hack-A-Thon
Careers GfG Weekly Contest
In Media Offline Classes (Delhi/NCR)
Contact Us DSA in JAVA/C++
Advertise with us Master System Design
GFG Corporate Solution Master CP
Placement Training Program GeeksforGeeks Videos
Apply for Mentor Geeks Community

Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL Top 100 DSA Interview Problems
R Language DSA Roadmap by Sandeep Jain
Android Tutorial All Cheat Sheets

https://www.geeksforgeeks.org/functional-programming-paradigm/ 7/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks

Tutorials Archive

Data Science & ML HTML & CSS


Data Science With Python HTML
Data Science For Beginner CSS
Machine Learning Tutorial Web Templates
ML Maths CSS Frameworks
Data Visualisation Tutorial Bootstrap
Pandas Tutorial Tailwind CSS
NumPy Tutorial SASS
NLP Tutorial LESS
Deep Learning Tutorial Web Design

Python Computer Science


Python Programming Examples GATE CS Notes
Django Tutorial Operating Systems
Python Projects Computer Network
Python Tkinter Database Management System
Web Scraping Software Engineering
OpenCV Python Tutorial Digital Logic Design
Python Interview Question Engineering Maths

DevOps Competitive Programming


Git Top DS or Algo for CP
AWS Top 50 Tree
Docker Top 50 Graph
Kubernetes Top 50 Array
Azure Top 50 String
GCP Top 50 DP
DevOps Roadmap Top 15 Websites for CP

System Design JavaScript


High Level Design JavaScript Examples
Low Level Design TypeScript
UML Diagrams ReactJS
Interview Guide NextJS
Design Patterns AngularJS

https://www.geeksforgeeks.org/functional-programming-paradigm/ 8/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks

OOAD NodeJS
System Design Bootcamp Lodash
Interview Questions Web Browser

NCERT Solutions School Subjects


Class 12 Mathematics
Class 11 Physics
Class 10 Chemistry
Class 9 Biology
Class 8 Social Science
Complete Study Material English Grammar

Commerce UPSC Study Material


Accountancy Polity Notes
Business Studies Geography Notes
Economics History Notes
Management Science and Technology Notes
HR Management Economy Notes
Finance Ethics Notes
Income Tax Previous Year Papers

SSC/ BANKING Colleges


SSC CGL Syllabus Indian Colleges Admission & Campus Experiences
SBI PO Syllabus List of Central Universities - In India
SBI Clerk Syllabus Colleges in Delhi University
IBPS PO Syllabus IIT Colleges
IBPS Clerk Syllabus NIT Colleges
SSC CGL Practice Papers IIIT Colleges

Companies Preparation Corner


META Owned Companies Company-Wise Recruitment Process
Alphabhet Owned Companies Resume Templates
TATA Group Owned Companies Aptitude Preparation
Reliance Owned Companies Puzzles
Fintech Companies Company-Wise Preparation
EdTech Companies

https://www.geeksforgeeks.org/functional-programming-paradigm/ 9/10
2/15/24, 11:08 PM Functional Programming Paradigm - GeeksforGeeks

Exams More Tutorials


JEE Mains Software Development
JEE Advanced Software Testing
GATE CS Product Management
NEET SAP
UGC NET SEO - Search Engine Optimization
Linux
Excel

Free Online Tools Write & Earn


Typing Test Write an Article
Image Editor Improve an Article
Code Formatters Pick Topics to Write
Code Converters Share your Experiences
Currency Converter Internships
Random Number Generator
Random Password Generator

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

https://www.geeksforgeeks.org/functional-programming-paradigm/ 10/10

You might also like