Declare a function

Functions live at module scope or inside an impl. Every parameter has a type. Write -> Type for a meaningful return value; a function without it returns void.

The final expression is returned automatically. Add pub only when another module must import the function. main is the parameterless entry point and is not overloaded.

fn add(left: int, right: int) -> int {
  left + right
}

fn main() {
  println(add(3, 4))
}
Output & diagnostics
Expected:
7
Ctrl/⌘+Enter runs the current lesson.