# Functions

Functions are defined with `let`

, where we can also annotate both the parameter and return types.

Type inference is supported, so in many cases the types can be left off, in which case the correct type will be inferred from the definition.

Functions are (almost) first-class values, with the type of a function from type `a`

to type `b`

written as `a -> b`

. This means we can write higher-order functions:

When passing an argument to a higher-order function, it is often most practical to use an *anonymous function* (sometimes called a *lambda*), like this:

A shortcut notation, called *operator sections*, allows partial application of infix operators:

By enclosing an operator in parentheses we can treat it like any variable name:

And we can treat a variable as an infix operator by enclosing it in backticks:

Function values are restricted as follows:

Arrays of functions are not permitted.

A function cannot be returned from an

`if`

expression.A loop parameter cannot be a function.

However, it is fine to collect functions in tuples or records.