Lesson 2. Functions and functional programming
After reading lesson 2, you’ll be able to
- Understand the general idea of functional programming
- Define simple functions in Haskell
- Declare variables in Haskell
- Explain the benefits of functional programming
The first topic you need to understand when learning Haskell is, what is functional programming? Functional programming has a reputation for being a challenging topic to master. Although this is undoubtedly true, the foundations of functional programming are surprisingly straightforward. The first thing you need to learn is what it means to have a function in a functional programming language. You likely already have a good idea of what using a function means. In this lesson, you’ll see the simple rules that functions must obey in Haskell that not only make your code easier to reason about, but also lead to entirely new ways of thinking about programming.
Consider this
You and your friends are out getting pizza. On the menu are three sizes of pizza pie with three different prices:
- 18 inches for $20
- 16 inches for $15
- 12 inches for $10
You want to know which choice gives you the most pizza for your dollar. You want to write a function that will give you the dollar-per-square-inch cost of the pizza.