CHAPTER 2
What Is Functional Programming?
Functional programming, in its “purest” sense, is rooted in how functions, variables,
and values actually work in mathematics, which is different from how they typically
work in most programming languages.
Functional programming got its start before digital computers even existed. Many of
the theoretical underpinnings of computation were developed in the 1930s by mathematicians like Alonzo Church and Haskell Curry.
In the 1930s, Alonzo Church developed the Lambda Calculus, which is a formalism
for defining and invoking functions (called applyingthem). Today, the syntax and behavior of most programming languages reflect this model.
Haskell Curry (for whom the Haskell language is named) helped develop Combinatory
Logic, which provides an alternative theoretical basis for computation. Combinatory
Logic examines how combinators, which are essentially functions, combine to represent
a computation. One practical application of combinators is to use them as building
blocks for constructing parsers. They are also useful for representing the steps in a
planned computation, which can be analyzed for possible bugs and optimization opportunities.
More recently, Category Theory has been a fruitful source of ideas for functional programming, such as ways to structure computations so that side effects like IO (input
and output), which change the state of the “world,” are cleanly separated from code
with no side effects.
A lot of the literature on functional programming reflects its mathematical roots, which
can be overwhelming if you don’t have a strong math background. In contrast, objectoriented programming seems more intuitive and approachable. Fortunately, you can
learn and use the principles of functional programming without a thorough grounding
in mathematics.
đang được dịch, vui lòng đợi..