# The Layout Rule

Before we dive into working with functions in Haskell, let's explore the **layout rule**. The layout rule states that each definition at the same level must begin at the same line position (column) in the script. This allows us to determine the groupings of different definitions simply from **indentation**. Let's define a function that adds the squares of two numbers together:

```haskell
sumSquares x y = a + b
  where
    a = x ^ 2 -- (^) is the power function
    b = y ^ 2
    
ghci> sumSquares 2 5
29
```

From the indentation, it is obvious to Haskell that `a` and `b` are **local definitions** in the function `sumSquares`, defined using the `where` keyword. **Local definitions** exist as intermediate helper expressions for structuring our functions and making our code more readable. It is also possible to wrap the local variables `a` and `b` in curly braces to explicitly state the grouping in which case the layout does not matter (although it's considered best practice to use the layout rule to give our code better readability), but we need to also explicitly separate each local definition with `;`:

```haskell
sumSquares x y = a + b
  where
    {
      a = x ^ 2; -- we need to separate expressions with ';' in this case
      b = y ^ 2
    }

ghci> sumSquares 2 5
29
```


---

# 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/defining-functions-working-with-functions/the-layout-rule.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.
