Functions in Hades are first-class citizens with explicit type annotations on every parameter and on the return value. The interpreter validates those types on every call, giving you the safety of a statically-typed language while keeping the flexibility of an interpreted one.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ToberlerOhn/hades/llms.txt
Use this file to discover all available pages before exploring further.
Defining a function
Thefunc keyword opens a function definition. Parameters are declared with the same name: type syntax used for variables. After the parameter list, => introduces the return type, and the body lives inside curly braces.
nothing as its return type and omits the => expression (or uses => nothing explicitly):
Returning a value
The=> token is both the return-type arrow in the header and the return statement inside the body. When the interpreter encounters => inside a function body, it exits the function immediately and yields the expression that follows.
Type checking
The interpreter enforces types on both entry and exit:- Parameters — each argument is checked against the declared parameter type before the body runs.
- Return value — the value produced by
=>is checked against the declared return type. - Nothing returns — if a function is declared
=> intand execution reaches the end without hitting a=>, a runtime error is raised.
Recursive functions
Functions can call themselves. The interpreter resolves the name from the enclosing scope, so standard recursive patterns work without any forward-declaration ceremony.Closures
Functions capture the scope in which they are defined — a function can read and modify variables from its surrounding scope even after that scope is no longer the active one. This is standard lexical-closure behaviour.No redefinition
Once a function name is declared, it cannot be redefined. Attempting to declare a second function with the same name in the same scope raises a runtime error:This restriction applies to the current scope. Functions defined inside a nested block (such as inside another function body) have their own scope and do not conflict with outer names.
Built-in functions
Hades ships with a small set of built-in functions available everywhere:| Function | Signature | Description |
|---|---|---|
print | print(...) | Prints all arguments concatenated with no separator |
type | type(value) | Returns the Hades type name of value as a str |
len | len(value) | Returns the length of a str or list |