# 4 Steps to Defining Recursive Functions

A good set of steps to follow when defining recursive functions is:

1. **Define the function type**

   Thinking about function types is very helpful when defining functions, and explicitly

   defining the function type is good practice.
2. **Enumerate different cases**

   Considering the general cases we expect allows us to create the function structure that we can then fill out gradually. For example, two standard cases for lists are empty and non-empty lists.
3. **Take care of the simple cases first (usually base cases)**

   The simple cases are usually straightforward so it's easier to define them. For example, our

   `sumN 0 = 0` is a simple case and also the base case.
4. **Define the other cases**

   Here, we have to think about how to calculate the wanted result using both the recursive call

   on the function itself and any other functions we might need. For example, in `sumN x = x sumN (x - 1)` we used both the `(+)` and `(-)` functions.


---

# 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/recursion/4-steps-to-defining-recursive-functions.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.
