Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
How to define functions
Function definitions start with
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.