func keyword and can live at module scope as free functions, or inside a type body as instance methods. This page covers every function-related keyword — func, type func, init, async func, and await — as well as the local binding keywords let and var and the return statement.
func — Free Functions and Instance Methods
Use func to declare a named function. A func at module scope is a free function; a func inside an object or value body is an instance method and receives an implicit this reference.
Syntax:
- All parameters are named.
- In v0.1, parameters are either all positional or all named at the call site — you cannot mix styles.
- The return type follows
:after the parameter list. Omit the return type annotation for functions that return nothing (void).
type func — Type-Owned Static Functions
A type func belongs to the type itself rather than to any instance. It has no this receiver and is called directly on the type name.
Syntax:
- Declared inside a
valueorobjectbody. - Called as
TypeName.methodName(...). - Cannot access instance members because there is no
this.
init — Object Initialiser
Every object has exactly one init in v0.1. The init sets up the initial state of the object by assigning values to this.member.
Syntax:
- Always called with named arguments at the call site:
TypeName(param: value). - The
initbody may only contain assignments tothismembers and calls to other initialisation helpers. - Only one
initperobjectis allowed in v0.1.
Named-argument call syntax at the
init call site is mandatory. Positional construction (e.g., Invoice("INV-001", 299.99)) is not valid.async func — Suspendable Functions
Mark a function with async to declare that it may suspend while waiting for an asynchronous result. An async func can contain await expressions.
Syntax:
- An
async funcmust be called withawaitat the call site. - Calling an
async funcwithoutawaitis a compile-time error.
await — Explicit Suspension Point
Use await to suspend execution until an asynchronous operation completes. Every suspension is explicit — Kairo does not automatically promote synchronous calls into async contexts.
Syntax:
awaitmay only appear inside anasync func.awaitdoes not unwrap aResult— it only suspends the current function until the awaited operation resolves.- If the awaited function returns
Result<T, E>, you still need to inspect.isSuccessor pattern-match the result yourself.
let — Immutable Local Binding
Use let to declare an immutable local variable. Once bound, the value cannot be reassigned.
- The type annotation is optional when the compiler can infer it from a simple literal or obvious expression.
- Attempting to reassign a
letbinding is a compile-time error.
var — Mutable Local Binding
Use var to declare a local variable whose value can be reassigned. An explicit type annotation is required in v0.1.
Local
var bindings always require an explicit type in v0.1. Type inference for mutable locals is planned for a future release.return Statement
Use return to exit a function and optionally produce a value. In a void function, a bare return exits early. In a function with a return type, return must be followed by an expression of the declared type.
Complete Example
The following module demonstrates free functions, instance methods, atype func, and an init together.
