Higher-order functions allow common programming patterns to be encapsulated as functions.

## Basic Concepts

A function that takes a function as an argument or returns a function as a result is called a higher-order function. Because the term curried already exists for returning functions as results, the term higher-order is often just used for taking functions as arguments.

## Processing Lists

The standard library defines a number of useful higher-order functions for processing lists.

## The foldr Function

Many functions that take a list as their argument can be defined using the following pattern of recursion on lists:

The function maps the empty list to a value `v`, and any non-empty list to an operator `#` applied to the head of the list and the result of recursively processed tail.

For example:

The higher-order library function foldr (fold right) encapsulates this pattern of recursion for defining functions on lists.

Fold right function assumes that the given operator associates to the right: `1+(2+(3+0))`.

It is easier to reason about `foldr f v` in a non-recursive way, as simply replacing each `:` (cons) operator in a list by the function `f`, and the empty list at the end by the value `v`.

For example, applying the function `foldr (+) 0` to the list `1 : (2 : (3 : []))` gives the result `1 + (2 + (3 + 0))` in which `:` and `[]` have been replaced by `+` and `0`.

A quick reminder: `[1,2,3]` and `1 : (2 : (3 : []))` are equivalent.

Many functions can be redefined with `foldr`:

## The foldl Function

Opposite of `foldr`, assumes that operator associates to the left: `((0+1)+2)+3`.

It is useful for mapping the empty list to the accumulator value `v`, and any non-empty list to the result of recursively processing the tail using a new accumulator value obtained by applying an operator `#` to the current value and the head of the list.

When a function can be defined using both `foldr` and `foldl` the choice of which definition is preferable is usually based on efficiency and requires considering the evaluation mechanism of Haskell.

## The Composition Operator

The standard operator `.` returns the composition of two functions as a single function.

Continuing later on.