Skip to main content Accessibility help
Internet Explorer 11 is being discontinued by Microsoft in August 2021. If you have difficulties viewing the site on Internet Explorer 11 we recommend using a different browser such as Microsoft Edge, Google Chrome, Apple Safari or Mozilla Firefox.

Chapter 1: Introduction

Chapter 1: Introduction

pp. 3-13

Authors

, University of Nottingham
Resources available Unlock the full potential of this textbook with additional resources. There are Instructor restricted resources available for this textbook. Explore resources
  • Add bookmark
  • Cite
  • Share

Summary

In this chapter we set the stage for the rest of the book. We start by reviewing the notion of a function, then introduce the concept of functional programming, summarise the main features of Haskell and its historical background, and conclude with three small examples that give a taste of Haskell.

Functions

In Haskell, a function is a mapping that takes one or more arguments and produces a single result, and is defined using an equation that gives a name for the function, a name for each of its arguments, and a body that specifies how the result can be calculated in terms of the arguments.

For example, a function double that takes a number x as its argument, and produces the result x + x, can be defined by the following equation:

double x = x + x

When a function is applied to actual arguments, the result is obtained by substituting these arguments into the body of the function in place of the argument names. This process may immediately produce a result that cannot be further simplified, such as a number. More commonly, however, the result will be an expression containing other function applications, which must then be processed in the same way to produce the final result.

For example, the result of the application double 3 of the function double to the number 3 can be determined by the following calculation, in which each step is explained by a short comment in curly parentheses:

double 3

= {applying double}

3 + 3

= {applying +}

6

Similarly, the result of the nested application double (double 2) in which the function double is applied twice can be calculated as follows:

double (double 2)

= {applying the inner double}

double (2 + 2)

= {applying +}

double 4

= {applying double}

4 + 4

= {applying +}

8

Alternatively, the same result can also be calculated by starting with the outer application of the function double rather than the inner:

double (double 2)

= {applying the outer double }

double 2 + double 2

= {applying the first double }

(2 + 2) + double 2

= {applying the first + }

4 + double 2

= {applying double }

4 + (2 + 2)

= {applying the second + }

4 + 4

= {applying + }

8

About the book

Access options

Review the options below to login to check your access.

Purchase options

eTextbook
US$47.00
Paperback
US$47.00

Have an access code?

To redeem an access code, please log in with your personal login.

If you believe you should have access to this content, please contact your institutional librarian or consult our FAQ page for further information about accessing our content.

Also available to purchase from these educational ebook suppliers