Skip to content

Functions and bindings

rockofox edited this page Jan 13, 2024 · 3 revisions

Indigo doesn't differentiate between functions and bindings. They are both defined using the let keyword.

let name = "Rocko"
let main = println "Hello " : name

The above code defines a binding name and a function main. The function main is called when the program is run.

let multiple_args (a: Int b: Int) => Int = a + b
let main = print (multiple_args 2, 3)

Functions can have multiple arguments. The above function adds two integers. Specifying the return type is optional, specifying parameter types is mandatory currently.

let println (s: String) => IO = do
    print s
    print "\n"
end

The above code shows the source code of the println function. As you can see here, the return type of IO actions is IO. Such functions can only used in functions that also return IO. Also, this example shows how it is possible to group statements using do and end.

Clone this wiki locally