# Functions

### Functions

SMLL is said to be a functional programming language, that is to say, functions are first-class citizens in this language. Functions can be created, called, stored, passed to functions and returned from other functions. In this section I am just going to introduce the basic usage and creation of functions in SMLL.&#x20;

{% hint style="info" %}
In SMLL all functions have a return type and must always return a value, even unit is a value.
{% endhint %}

{% code lineNumbers="true" %}

```sml
fn main(): Unit => {
    val sum = add(20, 50)
    val result  = "20 + 50 is = " + sum
    display(result)     
    ()
}

fn add(x: Int, y: Int): Int => x + y
fn display(answer: String): Unit => println(name)
```

{% endcode %}

Functions are declared with the fun keyword, followed by a name, arguments and the return type. Then an arrow operator is expected, separating the function header with the body. After the array is a single expression. SMLL functions execute a single expression, even blocks are expressions and blocks can contain more than 1 expressions such that the last one is the return value. Similar to standard compiled programming languages, the entry point of the program is main and functions can be declared anywhere.&#x20;


---

# 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://smllang.gitbook.io/home/basics/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.
