1 - What is functional programming?
Published online by Cambridge University Press: 05 November 2014
Summary
In a nutshell:
• Functional programming is a method of program construction that emphasises functions and their application rather than commands and their execution.
• Functional programming uses simple mathematical notation that allows problems to be described clearly and concisely.
• Functional programming has a simple mathematical basis that supports equational reasoning about the properties of programs.
Our aim in this book is to illustrate these three key points, using a specific functional language called Haskell.
Functions and types
We will use the Haskell notation
f :: X → Y
to assert that f is a function taking arguments of type X and returning results of type Y. For example,
sin :: Float → Float
age :: Person → Int
add :: (Integer,Integer) → Integer
logBase :: Float → (Float → Float)
Float is the type of floating-point numbers, things like 3.14159, and Int is the type of limited-precision integers, integers n that lie in a restricted range such as −229 ≤ n < 229. The restriction is lifted with the type Integer, which is the type of unlimited-precision integers. As we will see in Chapter 3, numbers in Haskell come in many flavours.
In mathematics one usually writes f(x) to denote the application of the function f to the argument x.
- Type
- Chapter
- Information
- Thinking Functionally with Haskell , pp. 1 - 21Publisher: Cambridge University PressPrint publication year: 2014