Skip to content

How to define functions

apaj edited this page Dec 18, 2017 · 1 revision

Function definitions start with def.

Function name follows.

Function parameters are given in the form of comma-separated list in parentheses, after the name. Each of the parameters, must be be followed by a colon and a type annotation.

Function result type is defined by the colon and another type annotation, after the parentheses. Following the function's result type is an equals sign and pair of curly braces that contain the body of the function.

In cases when the interpreter or compiler can infer the function result type, it does not have to be specified. However, if, for example, the function is recursive, the result type must be explicitly specified.

If a function consists of just one statement, the curly braces may be left out.

Clone this wiki locally