hanki

5. Functions and actions

Both pure functions and actions use the keyword def; the ! suffix on the name decides which it is. These are the first two of Hanki's three layers (§1, The three layers); the third - actors (§15) - is built from actions.

A pure function has no side effects and may not call any action.

def sum(x: i32, y: i32) -> i32
  x + y
end

An action may have side effects. Action names always end in !. The function type carries an optional effect annotation […] after the return type.

use io

def print_hello!(name: string) -> () [io]
  io.print!("Hello, #{name}")
end

Rules: