Computer Science
Functional Programming
Functional programming is a programming paradigm that emphasizes the use of functions to solve problems. It is based on the principles of mathematical functions and avoids changing state and mutable data. Functional programming languages include Haskell, Lisp, and ML.
Written by Perlego with AI-assistance
Related key terms
1 of 5
11 Key excerpts on "Functional Programming"
- eBook - PDF
- Arvind Kumar Bansal(Author)
- 2013(Publication Date)
- Chapman and Hall/CRC(Publisher)
325 C H A P T E R 9 Functional Programming Paradigm BACKGROUND CONCEPTS Abstract computation and information exchange (Chapter 4); Abstract concepts in com-putation (Section 2.4); Abstract implementation (Chapter 5); Concurrent programming (Chapter 8); Data structure concepts (Section 2.3), Discrete structure concepts (Section 2.2), von Neumann machine (Section 2.1 ). Declarative programming hides the control from the programmer. The resulting program is reflective of the underlying logic and is easier to maintain than imperative programs except for the unfamiliar syntax of some declarative languages. There are two major declarative programming paradigms: Functional Programming and logic programming. Mathematical functions are the basis of Functional Programming, and predicate calculus is the basis of the logic programming. Both mathematical models have been studied for decades and are sound. In this chapter, we will study Functional Programming. Functional Programming is important from many aspects: (1) declarative style hides the control from a programmer; program is only logic + abstraction; (2) functional programs are more concise than imperative programs; (3) Functional Programming is becoming a key paradigm that is being integrated in recent popular languages including many script-ing languages such as Clojure, Ruby, Scala, and Python ; and (4) functions are an important part of almost all programming languages. The work on Functional Programming started as early as 1960s with the development of the language Lisp. Although many scientists disagree with the purity of functional pro-gramming in Lisp, its contribution to Functional Programming is undeniable. Lisp con-tributed many abstractions such as high-level representation of lists, meta-programming, higher-order functions, and recursive style of programming. Variables in a pure functional program are immutable assign-once value holders. - No longer available |Learn more
Programming Languages
Principles and Practices
- Kenneth Louden, Kenneth Lambert(Authors)
- 2020(Publication Date)
- Cengage Learning EMEA(Publisher)
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. 50 CHAPTER 3 Functional Programming We can summarize the qualities of Functional Programming languages and functional programs as follows: 1. All procedures are functions and clearly distinguish incoming values (parameters) from outgoing values (results). 2. In pure Functional Programming, there are no assignments. Once a variable is bound to a value, it behaves like a constant. 3. In pure Functional Programming, there are no loops. Instead, loops are replaced by recursive calls. 4. The value of a function depends only on the value of its parameters and not on the order of evaluation or the execution path that led to the call. 5. Functions are first-class data values. 3.2 Scheme: A Dialect of Lisp In the late 1950s and early 1960s, a team at MIT led by John McCarthy developed the first language that contained many of the features of modern functional languages. Based on ideas from mathematics, in particular the lambda calculus of Alonzo Church, it was called Lisp (for LISt Processing) because its basic data structure is a list. Lisp, which first existed as an interpreter on an IBM 704, incorporated a number of features that, strictly speaking, are not aspects of Functional Programming per se, but that were closely associated with functional languages because of the enormous influence of Lisp. These include: 1. The uniform representation of programs and data using a single general data structure—the list. - eBook - PDF
Functional Programming in C#
Classic Programming Techniques for Modern Projects
- Oliver Sturm(Author)
- 2011(Publication Date)
- Wiley(Publisher)
PART I Introduction to Functional Programming CHAPTER 1: A Look at Functional Programming History CHAPTER 2: Putting Functional Programming into a Modern Context A Look at Functional Programming History WHAT’S IN THIS CHAPTER? An explanation Functional Programming A look at some functional languages The relationship to object oriented programming Functional Programming has been around for a very long time. Many regard the advent of the language LISP, in 1958, as the starting point of Functional Programming. On the other hand, LISP was based on existing concepts, perhaps most importantly those defined by Alonzo Church in his lambda calculus during the 1930s and 1940s. That sounds highly mathematical, and it was — the ideas of mathematics were easy to model in LISP, which made it the obvious language of choice in the academic sector. LISP introduced many other concepts that are still important to programming languages today. WHAT IS Functional Programming? In spite of the close coupling to LISP in its early days, Functional Programming is generally regarded a paradigm of programming that can be applied in many languages — even those that were not originally intended to be used with that paradigm. Like the name implies, it focuses on the application of functions. Functional programmers use functions as building blocks to create new functions — that’s not to say that there are no other language elements available to them, but the function is the main construct that architecture is built from. Referential transparency is an important idea in the realm of Functional Programming. A function that is referentially transparent returns values that depend only on the input parameters that are passed. This is in contrast to the basic ideas of imperative programming, ➤ ➤ ➤ 1 4 ❘ CHAPTER 1 A LOOK AT Functional Programming HISTORY where program state often influences return values of functions. - No longer available |Learn more
- John Paul Mueller(Author)
- 2019(Publication Date)
- For Dummies(Publisher)
In some respects, this makes languages that support the Functional Programming paradigm similar to applications such as MATLAB. Of course, with MATLAB, you get a user interface, which reduces the learning curve. However, you pay for the convenience of the user interface with a loss of power and flexibility, which functional languages do offer. Using this approach to defining a problem relies on the declarative programming style, which you see used with other paradigms and languages, such as Structured Query Language (SQL) for database management. In contrast to other paradigms, the Functional Programming paradigm doesn’t maintain state. The use of state enables you to track values between function calls. Other paradigms use state to produce variant results based on environment, such as determining the number of existing objects and doing something different when the number of objects is zero. As a result, calling a functional program function always produces the same result given a particular set of inputs, thereby making functional programs more predictable than those that support state. Because functional programs don’t maintain state, the data they work with is also immutable, which means that you can’t change it. To change a variable’s value, you must create a new variable. Again, this makes functional programs more predictable than other approaches and could make functional programs easier to run on multiple processors. The following sections provide additional information on how the Functional Programming paradigm differs. Understanding its goals Imperative programming, the kind of programming that most developers have done until now, is akin to an assembly line, where data moves through a series of steps in a specific order to produce a particular result. The process is fixed and rigid, and the person implementing the process must build a new assembly line every time an application requires a new result - eBook - PDF
- Michael Hammond(Author)
- 2020(Publication Date)
- Cambridge University Press(Publisher)
11 Functional Programming In this chapter, we introduce Functional Programming, a style of programming that grows out of the lambda calculus. Some aspects of functional program- ming are commonly used in Python, and so it’s useful to understand the general principles, if only to make sense of code written by others. This style of pro- gramming also lends itself easily to parallel programming and the resulting efficiencies, so this is an additional benefit. This chapter focuses on advanced material, so if you’re new to programming or feel unsure of your foundations at this stage, proceed carefully! 11.1 Functional Programming Generally Functional Programming is an ideal and in practice exists at various approx- imations to this ideal. The ideal is lambda calculus: everything is a function. What this means is two things. First, everything else goes: variables, state- ments, numbers, strings, etc. Second, functions are really functions; some set of values is mapped to some other value, with no side effects, no variability in what the function maps to. Python is not the perfect vehicle for Functional Programming, so the ideal is not completely reached with it, or at least not easily. In practice, what this means is the following: ● We avoid global variables. ● Variables are not used mutably. ● Functions are freely used as arguments to other functions and can be returned from functions. ● Functions can be created anonymously with lambda when needed. ● Recursion, overt or covert, is used widely. ● Control structures are avoided or not used at all. Their work is done by functions and comprehensions. We’ve covered some of these topics to varying degrees already, but let’s go through each of them now in the context of Functional Programming generally. 261 262 Functional Programming 11.2 Variables, State, and Mutability State refers to the value of variables at any particular point in the execution of a program. - eBook - PDF
- Adam Olszewski, Jan Wolenski, Robert Janusz, Adam Olszewski, Jan Wolenski, Robert Janusz(Authors)
- 2013(Publication Date)
- De Gruyter(Publisher)
Backus [1978] calls them “von Neumann languages”. Functional 8 programming languages offer a radical alternative— they are descriptive rather than imperative, have no assignment com-mand and no explicit flow of control—sub–computations are ordered only partially, by data dependency. The claimed merits of Functional Programming—in conciseness, mathematical tractability, potential for parallel execution—have been argued in many places so we will not dwell on them here. Nor will we go into the history of the concept, other than to say that the basic ideas go back over four decades, see in particular the important early papers of McCarthy [1960], Landin [1966]—and that for a long period Functional Programming was mainly practised in imperative languages with functional subsets (LISP, Scheme, Standard ML). The disadvantages of Functional Programming within a language that includes imperative features are two. First, you are not forced 8 We here use functional to mean what some call purely functional , an older term for this is applicative , yet another term which includes other mathematically based models, such as logic programming, is declarative . Church’s Thesis and Functional Programming 529 to explore the limits of the functional style, since you can escape at will into an imperative idiom. Second, the presence of side effects, exceptions etc., even if they are rarely used , invalidate important theorems on which the benefits of the style rest. The λ -calculus is the most natural candidate for functional pro-gramming: it is computationally complete in the sense of Church’s Thesis, it includes functions of higher type and it comes with a the-ory of λ -conversion that provides a basis for reasoning about pro-gram transformation, correctness of evaluation mechanisms and so on. The notation is a little spartan for most tastes but it was shown long ago by Peter Landin that the dish can be sweetened by adding a sprinkling of syntactic sugar. - eBook - PDF
Programming with Mathematica®
An Introduction
- Paul Wellin(Author)
- 2013(Publication Date)
- Cambridge University Press(Publisher)
5 Functional Programming Higher-order functions · Map · Apply · Thread and MapThread · The Listable attribute · Inner and Outer · Select and Pick · Iterating functions · Nest · FixedPoint · NestWhile · Fold · Defining functions · Compound functions · Scoping constructs · Pure functions · Options · Creating and issuing messages · Hamming distance · Josephus problem · Regular polygons · Protein interaction networks · Palettes for project files · Operating on arrays Functional Programming, the use and evaluation of functions as a programming paradigm, has a long and rich history in programming languages. Lisp came about in the search for a convenient language for representing mathematical concepts in programs. It borrowed from the lambda calculus of the logician Alonzo Church. More recent languages have in turn embraced many aspects of Lisp – in addition to Lisp’s offspring such as Scheme and Haskell, you will find ele- ments of functional constructs in Java, Python, Ruby, and Perl. Mathematica itself has clear bloodlines to Lisp, including the ability to operate on data structures such as lists as single objects and in its representation of mathematical properties through rules. Being able to express ideas in science, mathematics, and engineering in a language that naturally mirrors those fields is made much easier by the integration of these tools. Functions not only offer a familiar paradigm to those representing ideas in science, mathemat- ics, and engineering, they provide a consistent and efficient mechanism for computation and programming. In Mathematica, unlike many other languages, functions are considered “first class” objects, meaning they can be used as arguments to other functions, they can be returned as values, and they can be part of many other kinds of data objects such as arrays. In addition, you can create and use functions at runtime, that is, when you evaluate an expression. - eBook - ePub
Functional Programming in JavaScript
How to improve your JavaScript programs using functional techniques
- Luis Atencio(Author)
- 2016(Publication Date)
- Manning(Publisher)
chapter 2 .Writing functional JavaScript code addresses most of these concerns. Using a set of proven techniques and practices based on pure functions, you can write code that is easy to reason about in the face of increasing complexity. Writing JavaScript functionally is a two-for-one deal, because you not only improve the quality of your entire application, but also gain more proficiency in and a better understanding of the JavaScript language.Because Functional Programming isn’t a framework or a tool, but a way of writing code, thinking functionally is radically different from thinking in object-oriented terms. But how do you become functional? How do you begin to think functionally? Functional Programming is intuitive once you’ve grasped its essence. Unlearning old habits is the hardest part and can be a huge paradigm shift for most people who come from an object-oriented background. Before you can learn to think functionally, first you must learn what FP is.1.2. What is Functional Programming?
In simple terms, Functional Programming is a software development style that places a major emphasis on the use of functions. You might say, “Well, I already use functions on a day-to-day basis at work; what’s the difference?” As I mentioned earlier, FP requires you to think a bit differently about how to approach the tasks you’re facing. It’s not a matter of just applying functions to come up with a result; the goal, rather, is to abstract control flows and operations on data with functions in order to avoid side effects and reduce mutation of state in your application. I know this sounds like a mouthful, but I’ll visit each of these terms further and build on them throughout the book.Normally, FP books start with computing Fibonacci numbers, but I’d rather start with a simple JavaScript program that displays text on an HTML page. What better text to print than the good ol’ “Hello World”: - eBook - PDF
- Darrel Ince, Derek Andrews(Authors)
- 2014(Publication Date)
- Butterworth-Heinemann(Publisher)
In practice, functional programs written without considering these issues may well be inefficient or even unrunnable, but this may be acceptable for early and intermediate representations (i.e. specifications of one sort or another). 26 The software life cycle For example, the order in which independent subexpressions are evaluated is not constrained by a purely functional program. A particular order may be decided on in due course, or a nondeterministic order, or parallel evaluation if this is feasible. This is information about the functional program which can be added at a later stage of development. In contrast, expressing a representation in a conventional language requires this kind of decision, even if it is not appropriate at the current stage of development. If it is stated that an operation involves three suboperations and then combines their results in some way, it is necessary to decide whether this should be expressed as a sequence of three procedure calls, for example, or three parallel tasks. With regard to data storage, functional languages tend to use dynamic (recursive) data structures such as lists and trees rather than arrays and record-structures. Data structures in functional programs are not updated by destructive assignment: new modified structures are constructed using copies of old values; old structures that are no longer referenced by any expression are garbage-collected at run time. In practice, generalized data structures and nondestructive updating may lead to inefficiencies. However, as with scheduling, information about optimized data structures and destructive updating can be added to a functional representation at a later stage of development. To summarize, it is necessary to factor out the different kinds of information that make up a system of executable software, and allow this information to be introduced at different stages of development. - eBook - PDF
Programming Language Fundamentals
A Metalanguage Approach in Elm
- Martin Erwig(Author)
- 2024(Publication Date)
- Wiley(Publisher)
2 Functional Programming with Elm Chapter Summary An introduction to the basics of Functional Programming using the language Elm. Working with expressions and names in the Elm interpreter. Definition and use of functions, in particular, the concept of currying and partial function application. Recursion and how it relates to iteration. Lists, pattern matching, and the basics of general data types. (More details and examples of data types to follow in later chapters where they are used for representing syntax, semantics, and type systems.) The concept of higher-order functions and their use as as control structures. In imperative languages, such as C, Java, or Python, computation is expressed as transformations of state, that is, the underlying programming model views a program as a series of statements that perform successive changes to a state, which can be accessed through names called variables. For example, if a pro- gram declares an integer variable x, then the assignment x = 3 has the effect that referencing the variable x afterwards will yield the value 3, at least until x is changed by another assignment. The functional core of Elm does not have an underlying global state that can be manipulated. Specifically, Elm does not have an assignment operation for changing the values of variables. It doesn’t have while or for loops either. Elm is a Functional Programming language, in which every computation is ex- pressed as a function. A function has one or more parameters and is defined by an expression (also called the function’s body) that can refer to these parame- Programming Language Fundamentals: A Metalanguage Approach in Elm, First edition. Martin Erwig. © 2024 Martin Erwig. Published 2024 by John Wiley & Sons Inc. Companion website: www.wiley.com/go/ProgrammingLanguageFun 14 2 Functional Programming with Elm Concept Elm C, Java, etc. - eBook - PDF
- John C. Mitchell(Author)
- 2002(Publication Date)
- Cambridge University Press(Publisher)
Two examples are Lisp and ML. Both of these languages contain declarative and im-perative constructs. However, it is possible to write a substantial program in either language without using any imperative constructs. Some people use the phrase functional language to refer to languages that do not have expressions with side effects or any other form of imperative construct. 78 Fundamentals However, we will use the more emphatic phrase pure functional language for declar-ative languages that are designed around flexible constructs for defining and using functions. We learned in Subsection 3.4.9 that pure Lisp, based on atom, eq, car, cdr, cons, lambda, define , is a pure functional language. If rplaca , which changes the car of a cell, and rplacd , which changes the cdr of a cell, are added, then the resulting Lisp is not a pure functional language. Pure functional languages pass the following test: Declarative Language Test : Within the scope of specific declarations of x 1 , ..., x n , all occurrences of an expression e containing only variables x 1 , ..., x n have the same value. As a consequence, pure functional languages have a useful optimization property: If expression e occurs several places within a specific scope, this expression needs to be evaluated only once. For example, suppose a program written in pure Lisp contains two occurrences of (cons a b) . An optimizing Lisp compiler could compute (cons a b) once and use the same value both places. This not only saves time, but also space, as evaluating cons would ordinarily involve a new cell. Referential Transparency In some of the academic literature on programming languages, including some text-books on programming language semantics, the concept that is used to distinguish declarative from imperative languages is called referential transparency . Although it is easy to define this phrase, it is a bit tricky to use it correctly to distinguish one programming language from another.
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.










