Computer Science
Functional Programming Languages
Functional programming languages are a type of programming language that emphasizes the use of functions to solve problems. They are designed to avoid side effects and mutable data, instead using immutable data structures and pure functions. Examples of functional programming languages include Haskell, Lisp, and ML.
Written by Perlego with AI-assistance
Related key terms
1 of 5
10 Key excerpts on "Functional Programming Languages"
- No longer available |Learn more
- John Paul Mueller(Author)
- 2019(Publication Date)
- For Dummies(Publisher)
(The next section, “Discovering Languages that Support Functional Programming,” describes the available languages in more detail.) In fact, you may even be performing functional programming tasks in your current language without realizing it. Every time you create and use a lambda function, you’re likely using functional programming techniques (in an impure way, at least). In addition to using lambda functions, languages that implement the functional programming paradigm have some other features in common. Here is a quick overview of these features: First-class and higher-order functions: First-class and higher-order functions both allow you to provide a function as an input, as you would when using a higher-order function in calculus. Pure functions: A pure function has no side effects. When working with a pure function, you can Remove the function if no other functions rely on its output Obtain the same results every time you call the function with a given set of inputs Reverse the order of calls to different functions without any change to application functionality Process the function calls in parallel without any consequence Evaluate the function calls in any order, assuming that the entire language doesn’t allow side effects Recursion: Functional language implementations rely on recursion to implement looping. In general, recursion works differently in functional languages because no change in application state occurs. Referential transparency: The value of a variable (a bit of a misnomer because you can’t change the value) never changes in a functional language implementation because functional languages lack an assignment operator. You often find a number of other considerations for performing tasks in functional programming language implementations, but these issues aren’t consistent across languages. For example, some languages use strict (eager) evaluation, while other languages use non-strict (lazy) evaluation - No longer available |Learn more
Programming Languages
Principles and Practices
- Kenneth Louden, Kenneth Lambert(Authors)
- 2020(Publication Date)
- Cengage Learning EMEA(Publisher)
We begin with functional programming. Unlike other styles of programming, functional program-ming provides a uniform view of programs as functions, the treatment of functions as data, and the prevention of side effects. Generally speaking, a functional programming language has simpler semantics and a simpler model of computation than an imperative language. These advantages make functional languages popular for rapid prototyping, artificial intelligence, mathematical proof systems, and logic applications. Until recently, the major drawback to functional languages was inefficient execution. Because of their semantics, such languages at first were interpreted rather than compiled, with a resulting substantial loss in execution speed. In the last 20 years, however, advances in compilation techniques for functional languages, plus advances in interpreter technology in cases where compilation is unsuitable or unavail-able, have made functional languages very attractive for general programming. Because functional programs lend themselves very well to parallel execution, functional languages have ironically acquired an efficiency advantage over imperative languages in the present era of multicore hardware architectures (see Chapter 13). Additionally, modern functional languages such as those discussed in this chapter include mature application libraries, such as windowing systems, graphics packages, and networking capabilities. If speed is a special concern for part of a program, you can link a functional program to compiled code from other languages such as C. Thus, there is no reason today not to choose a functional language for implementing complex systems—even Web applications. A functional language is a particu-larly good choice in situations where development time is short and you need to use clear, concise code with predictable behavior. Still, although functional languages have been around since the 1950s, they have never become mainstream languages. - eBook - PDF
- John Paul Mueller(Author)
- 2020(Publication Date)
- For Dummies(Publisher)
Every time you create and use a lambda function, you’re likely using functional programming techniques (in an impure way, at least). C ++ supports lambda functions through the lambda expressions that later sections of this chapter explore. In addition to using lambda functions, languages that implement the functional programming paradigm have some other features in common. Here is a quick overview of these features: » First-class and higher-order functions: First-class and higher-order func-tions both allow you to provide a function as an input, as you would when using a higher-order function in calculus. • Declarative: Functional programming actually implements the declarative pro-gramming paradigm, but the two paradigms are separate. Other paradigms, such as logic programming, implemented by the Prolog language, also support the declarative programming paradigm. The short view of declarative programming is that it does the following: describes what the code should do, rather than how to do it; defines functions that are referentially transparent (without side effects); and provides a clear correspondence to mathematical logic. 374 BOOK 3 Understanding Functional Programming » Pure functions: A pure function has no side effects. When working with a pure function, you can • Remove the function if no other functions rely on its output • Obtain the same results every time you call the function with a given set of inputs • Reverse the order of calls to different functions without any change to application functionality • Process the function calls in parallel without any consequence • Evaluate the function calls in any order, assuming that the entire language doesn’t allow side effects » Recursion: Functional language implementations rely on recursion to implement looping. In general, recursion works differently in functional languages because no change in application state occurs. - eBook - PDF
- Arvind Kumar Bansal(Author)
- 2013(Publication Date)
- Chapman and Hall/CRC(Publisher)
Another strategy is to defer the evaluation of expression until expression simplification is needed. This strategy to defer the evaluation until needed is called lazy evaluation , which has been described in Section 9.3. Lazy evaluation is used the functional programming language Haskell. Lazy evaluation uses either call-by-name or call-by-need. Functional programming has been combined with different programming paradigms such as imperative programming in the form of incorporating mutable objects, object-oriented programming paradigm, logic programming paradigm, and concurrent programming paradigm. Multiple multiparadigm languages such as Ruby and Scala have been developed. The primary data abstraction used in functional programming is sequence that is used for strings and collection of data-entities. Sequence was initially implemented using linked list. However, list is a high-level representation at a programmer’s level, and programmers do not have to explicitly manage the chain of pointers. That is a big change from imperative languages, where programmer has to explicitly write statements to use chain of pointers. Functional Programming Paradigm ◾ 327 Functional Programming Languages support higher-order functions, as it gives them capabilities to (1) treat other functions as data, (2) build a function as data and transform into function, and (3) build complex programs by joining multiple functions in variety of ways. A higher-order function can treat another function as its argument, and derive new complex function. Higher-order functions can be easily built using apply function that converts data into function. For example ( apply ‘square ‘(2)) will evaluate to give the func-tion ( square ‘2) that will evaluate to 4. Another example of a higher-level function is given in function ‘foo’ written in Lisp. - 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
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. - 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
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 - 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
- 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.









