SlideShare a Scribd company logo
COMPUTER SCENCE
9 . 2 4 . X X
FUNCTIONAL PARADIGM
Th e fu n c tion al p rog rammin g p arad ig m is
a sty le of p rog rammin g wh ere
comp u tation is treated as th e evalu ation
of math ematical fu n c tion s.
Th e F u n c tion al Parad ig m contrib u tes to
writin g rob u st, maintain ab le, an d
scalab le software, alig n in g well with th e
n eed s an d c h allen ges of mod ern software
d evelop ment.
2
INTRODUCTION
3
FUNCTIONAL ASPECTS IN C
Incorporating functional features into C involves using concepts from
functional programming to write more concise, modular, and
maintainable code. Some of the key functional features that can be
incorporated into C include:
• First-class functions
• Higher-order functions
• Recursion
• Immutable data
• Lambda expressions
Incorporating these functional features into C can lead to code that is
more expressive, easier to reason about, and less prone to bugs.
However, it is important to note that C is not a purely functional
language, and incorporating these features may require a different
mindset and approach to programming.
C is not a functional programming language, but functional
programming principles can be applied to C. However, it's important
to recognize that C's primary paradigm is procedural and imperative,
not functional, and adopting functional principles may require a
different approach and mindset.
3
4
PURE FUNCTIONS
Pure functions are functions that, given the same input, will
always return the same output and have no side effects. In
other words, they do not depend on or modify any state
outside of their scope.
In functional programming, pure functions are fundamental
building blocks, and their use promotes code that is easier to
understand, test, and maintain.
An example of a pure function in C that calculates the square of
a given integer without any side effects:
#include <stdio.h>
// A pure function to calculate the square of a number
int square(int x) {
return x * x;
}
int main() {
int num = 5;
int result = square(num); // Calling the pure function
printf("The square of %d is %dn", num, result);
return 0;
}
5
IMMUTABILITY IN C
Challenges of Immutability in C:
1.Lack of built-in support
2.Performance Impact
3.Complexity
Benefits of Immutability in C:
1.Safety: Immutable data can help prevent
unintended modifications
2.Easier reasoning
3.Thread safety: Immutable data can simplify
concurrent programming,
4.Functional programming: Immutability
aligns with functional programming principles
Incorporating immutability in C may require
careful consideration of trade-offs, but it can
lead to safer and more maintainable code,
particularly in scenarios where predictability
and thread safety are crucial.
const int x = 5; // declare x as a
constant integer with value 5
In this example we declare
x as a constant integer with
the value of 5 using the
const keyword. This means
we cannot modify the value
of x later in the program.
The const keyword can be
used with other data types
as well, such as pointers,
arrays, and structures, to
enforce immutability and
prevent unintended
modifications
6
HIGHER-ORDER FUNCTIONS
Higher-order functions are functions that can take other
functions as arguments or return functions as results. This
concept allows for the abstraction of common patterns and
behaviors, promoting code reusability and modularity. Higher-
order functions enable powerful techniques such as function
composition, currying, and partial application, and are a
fundamental aspect of functional programming, providing a
flexible and expressive way to manipulate and work with
functions as first-class citizens in programming languages.
Some examples of higher-order functions include:
1.Map: A function that takes a function and a list as input
and applies the function to each element of the list, returning
a new list with the transformed values.
2.Filter: A function that takes a function and a list as input and
returns a new list with only the elements that satisfy the
condition specified by the function.
3.Reduce: A function that takes a function, a list, and an initial
value as input and applies the function to the elements of the
list, reducing them to a single value.
7
RECURSION
Recursion in functional programming allows for problems to be
solved by breaking them down into smaller, self-referential
subproblems. It promotes a clear, mathematical approach to
problem-solving and aligns with the paradigm's emphasis on
immutability and pure functions. Recursion is especially effective
for handling nested data structures and tree-like data.
Here is an example of factorial calculation
#include <stdio.h>
int factorial(int n) {
if (n == 0 || n == 1) {
return 1; } else { return n * factorial(n - 1);
}
} int main() {
int num = 5; printf("Factorial of %d is %dn", num,
factorial(num)); return 0;
}
In this example, the factorial function is defined recursively to
calculate the factorial of a number.
FIRST-CLASS FUNCTIONS
First-class functions refer to functions that can be treated as first-
class citizens within a programming language. This means that
functions can be:
1.Assigned to variables and data structures.
2.Passed as arguments to other functions.
3.Returned as values from other functions.
In essence, first-class functions enable functions to be
manipulated and used in the same way as other data types,
allowing for powerful and flexible programming paradigms such
as functional programming, higher-order functions, and function
composition.
In C, first-class functions can be simulated using function
pointers. Function pointers allow functions to be assigned to
variables, passed as arguments, and returned from other
functions, effectively emulating first-class function behavior.
9
MANAGING STATE
In functional programming, managing state can
present several challenges due to the emphasis
on immutability and statelessness. Some of the
challenges related to state in functional
programming include:
1.Immutability
2.Side Effects
3.Stateful Operations
4.Asynchronous State:
5.Performance
Addressing these challenges often involves
leveraging functional programming techniques
such as monads, pure functions, and functional
data structures, as well as employing patterns like
event sourcing, immutable data structures, and
state monads to manage state in a functional
manner.
10
CONCLUSION
Key functional programming concepts in C include:
1.First-Class Functions: Function pointers in C treat functions like data, allowing them to be
manipulated and passed around like variables.
2. Higher-Order functions: C supports higher-order functions, allowing functions to take other
functions as arguments or return functions as results, promoting generic and reusable code.
3. Immutability: Functional programming encourages using immutable data structures and
values in C to minimize side effects and improve program clarity.
4. Pure Functions: Pure functions in C have no side effects and consistently return the same
output for the same input, making them predictable and easier to test and understand.
5. Recursion: Functional programming in C often uses recursion for iteration instead of
traditional loops, allowing for a functional approach to problem-solving.
6. Avoidance of Side Effects: Functional programming in C emphasizes avoiding side effects to
maintain predictability and referential transparency.
By leveraging these functional programming concepts, developers can write more modular,
composable, and maintainable code in C, even though the language is not purely functional.
THANK YOU
J e h v o u n B y f i e l d
Ke t o n B ro w n
+ 1 ( 8 7 6 ) 3 9 3 - 9 4 7 1
j e h v o u n b y f i e l d k c @ g m a i l . c o m

More Related Content

PPTX
Why functional programming in C# & F#
PDF
Functional programming
PDF
Functional Programming Principles & Patterns
PDF
Functional programming in C++
PPTX
Столпы функционального программирования для адептов ООП, Николай Мозговой
PPTX
Functional Programming in Swift
PDF
A (very brief) into to Functional Programming
PDF
Functional Programming for OO Programmers (part 1)
Why functional programming in C# & F#
Functional programming
Functional Programming Principles & Patterns
Functional programming in C++
Столпы функционального программирования для адептов ООП, Николай Мозговой
Functional Programming in Swift
A (very brief) into to Functional Programming
Functional Programming for OO Programmers (part 1)

Similar to Functional Paradigm.pptx (20)

PDF
"Functional Programming in a Nutshell" by Adityo Pratomo (Froyo Framework)
PDF
Functional Go
PDF
Introduction to Functional Programming
PDF
Rainer Grimm, “Functional Programming in C++11”
PDF
Intro to functional programming - Confoo
PDF
Functional programming techniques in regular JavaScript
PPTX
Intro f# functional_programming
ODP
Functional programming
PDF
Functional Programming in C#: How to write better C# code 1st Edition Enrico ...
PDF
introtofunctionalprogramming2-170301075633.pdf
PDF
Introduction to functional programming
PDF
Intro to functional programming
PDF
Introduction to functional programming (In Arabic)
PDF
Intro to functional programming
PDF
An Introduction to Functional Programming at the Jozi Java User Group
PDF
Intro to Functional Programming @ Scala Montreal
PPTX
Functional Programming.pptx
PDF
Introduction to functional programming
PPTX
Introduction to Functional programming
PDF
Functional go
"Functional Programming in a Nutshell" by Adityo Pratomo (Froyo Framework)
Functional Go
Introduction to Functional Programming
Rainer Grimm, “Functional Programming in C++11”
Intro to functional programming - Confoo
Functional programming techniques in regular JavaScript
Intro f# functional_programming
Functional programming
Functional Programming in C#: How to write better C# code 1st Edition Enrico ...
introtofunctionalprogramming2-170301075633.pdf
Introduction to functional programming
Intro to functional programming
Introduction to functional programming (In Arabic)
Intro to functional programming
An Introduction to Functional Programming at the Jozi Java User Group
Intro to Functional Programming @ Scala Montreal
Functional Programming.pptx
Introduction to functional programming
Introduction to Functional programming
Functional go
Ad

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation theory and applications.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Programs and apps: productivity, graphics, security and other tools
Building Integrated photovoltaic BIPV_UPV.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation_ Review paper, used for researhc scholars
Reach Out and Touch Someone: Haptics and Empathic Computing
Empathic Computing: Creating Shared Understanding
Encapsulation theory and applications.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Ad

Functional Paradigm.pptx

  • 1. COMPUTER SCENCE 9 . 2 4 . X X FUNCTIONAL PARADIGM
  • 2. Th e fu n c tion al p rog rammin g p arad ig m is a sty le of p rog rammin g wh ere comp u tation is treated as th e evalu ation of math ematical fu n c tion s. Th e F u n c tion al Parad ig m contrib u tes to writin g rob u st, maintain ab le, an d scalab le software, alig n in g well with th e n eed s an d c h allen ges of mod ern software d evelop ment. 2 INTRODUCTION
  • 3. 3 FUNCTIONAL ASPECTS IN C Incorporating functional features into C involves using concepts from functional programming to write more concise, modular, and maintainable code. Some of the key functional features that can be incorporated into C include: • First-class functions • Higher-order functions • Recursion • Immutable data • Lambda expressions Incorporating these functional features into C can lead to code that is more expressive, easier to reason about, and less prone to bugs. However, it is important to note that C is not a purely functional language, and incorporating these features may require a different mindset and approach to programming. C is not a functional programming language, but functional programming principles can be applied to C. However, it's important to recognize that C's primary paradigm is procedural and imperative, not functional, and adopting functional principles may require a different approach and mindset. 3
  • 4. 4 PURE FUNCTIONS Pure functions are functions that, given the same input, will always return the same output and have no side effects. In other words, they do not depend on or modify any state outside of their scope. In functional programming, pure functions are fundamental building blocks, and their use promotes code that is easier to understand, test, and maintain. An example of a pure function in C that calculates the square of a given integer without any side effects: #include <stdio.h> // A pure function to calculate the square of a number int square(int x) { return x * x; } int main() { int num = 5; int result = square(num); // Calling the pure function printf("The square of %d is %dn", num, result); return 0; }
  • 5. 5 IMMUTABILITY IN C Challenges of Immutability in C: 1.Lack of built-in support 2.Performance Impact 3.Complexity Benefits of Immutability in C: 1.Safety: Immutable data can help prevent unintended modifications 2.Easier reasoning 3.Thread safety: Immutable data can simplify concurrent programming, 4.Functional programming: Immutability aligns with functional programming principles Incorporating immutability in C may require careful consideration of trade-offs, but it can lead to safer and more maintainable code, particularly in scenarios where predictability and thread safety are crucial. const int x = 5; // declare x as a constant integer with value 5 In this example we declare x as a constant integer with the value of 5 using the const keyword. This means we cannot modify the value of x later in the program. The const keyword can be used with other data types as well, such as pointers, arrays, and structures, to enforce immutability and prevent unintended modifications
  • 6. 6 HIGHER-ORDER FUNCTIONS Higher-order functions are functions that can take other functions as arguments or return functions as results. This concept allows for the abstraction of common patterns and behaviors, promoting code reusability and modularity. Higher- order functions enable powerful techniques such as function composition, currying, and partial application, and are a fundamental aspect of functional programming, providing a flexible and expressive way to manipulate and work with functions as first-class citizens in programming languages. Some examples of higher-order functions include: 1.Map: A function that takes a function and a list as input and applies the function to each element of the list, returning a new list with the transformed values. 2.Filter: A function that takes a function and a list as input and returns a new list with only the elements that satisfy the condition specified by the function. 3.Reduce: A function that takes a function, a list, and an initial value as input and applies the function to the elements of the list, reducing them to a single value.
  • 7. 7 RECURSION Recursion in functional programming allows for problems to be solved by breaking them down into smaller, self-referential subproblems. It promotes a clear, mathematical approach to problem-solving and aligns with the paradigm's emphasis on immutability and pure functions. Recursion is especially effective for handling nested data structures and tree-like data. Here is an example of factorial calculation #include <stdio.h> int factorial(int n) { if (n == 0 || n == 1) { return 1; } else { return n * factorial(n - 1); } } int main() { int num = 5; printf("Factorial of %d is %dn", num, factorial(num)); return 0; } In this example, the factorial function is defined recursively to calculate the factorial of a number.
  • 8. FIRST-CLASS FUNCTIONS First-class functions refer to functions that can be treated as first- class citizens within a programming language. This means that functions can be: 1.Assigned to variables and data structures. 2.Passed as arguments to other functions. 3.Returned as values from other functions. In essence, first-class functions enable functions to be manipulated and used in the same way as other data types, allowing for powerful and flexible programming paradigms such as functional programming, higher-order functions, and function composition. In C, first-class functions can be simulated using function pointers. Function pointers allow functions to be assigned to variables, passed as arguments, and returned from other functions, effectively emulating first-class function behavior.
  • 9. 9 MANAGING STATE In functional programming, managing state can present several challenges due to the emphasis on immutability and statelessness. Some of the challenges related to state in functional programming include: 1.Immutability 2.Side Effects 3.Stateful Operations 4.Asynchronous State: 5.Performance Addressing these challenges often involves leveraging functional programming techniques such as monads, pure functions, and functional data structures, as well as employing patterns like event sourcing, immutable data structures, and state monads to manage state in a functional manner.
  • 10. 10 CONCLUSION Key functional programming concepts in C include: 1.First-Class Functions: Function pointers in C treat functions like data, allowing them to be manipulated and passed around like variables. 2. Higher-Order functions: C supports higher-order functions, allowing functions to take other functions as arguments or return functions as results, promoting generic and reusable code. 3. Immutability: Functional programming encourages using immutable data structures and values in C to minimize side effects and improve program clarity. 4. Pure Functions: Pure functions in C have no side effects and consistently return the same output for the same input, making them predictable and easier to test and understand. 5. Recursion: Functional programming in C often uses recursion for iteration instead of traditional loops, allowing for a functional approach to problem-solving. 6. Avoidance of Side Effects: Functional programming in C emphasizes avoiding side effects to maintain predictability and referential transparency. By leveraging these functional programming concepts, developers can write more modular, composable, and maintainable code in C, even though the language is not purely functional.
  • 11. THANK YOU J e h v o u n B y f i e l d Ke t o n B ro w n + 1 ( 8 7 6 ) 3 9 3 - 9 4 7 1 j e h v o u n b y f i e l d k c @ g m a i l . c o m