# Introduction

A **higher-order function** in Haskell is a function that either takes in a function as its argument or returns a function as its result. We have already seen how functions can return other functions as their result when we introduced [curried functions](/types-in-haskell/function-types/curried-functions.md), so we will focus on **functions that take other functions as arguments** in this chapter. First, let's look at a simple example of a higher-order function that takes in a function and applies it twice to an argument:

```haskell
applyTwice :: (a -> a) -> a -> a
applyTwice f x = f (f x)

ghci> applyTwice (++ " two") "one"
"one two two"
```

The function we passed in `(++ "two ")` simply appends the string `"two "` to the argument passed in (in this case, it must be a string), and it is applied twice when the higher-order function `applyTwice` is called.

Now let's take a closer look at two higher-order functions that are defined in the Prelude for working with lists, `map` and `filter`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://haskell.hpmeducation.com/higher-order-functions/introduction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
