Skip to main content
Kairo has one function keyword, func, and four ways to use it: free functions, instance methods, type functions, and async functions. Every signature is explicit. There is no overload resolution and no hidden receiver.

Free functions

A func declared at module scope is a free function.
  • Parameters are name: Type pairs separated by commas.
  • The return type follows the parameter list after a colon.
  • Omitting the return type means the function returns no value.

Instance methods

A func declared inside a value, object, or contract is an instance method.
  • Value methods have an immutable this receiver.
  • Object methods have an identity-bearing this and may mutate var members.
  • Contract methods are requirements: no body, just the signature.

Type functions

type func declares a function owned by the type itself, not by any instance. There is no this.
Use type func for named factories and type-scoped helpers. Kairo does not use static in v0.1.

Initialization

init runs once when an object is constructed. It cannot return a value and must assign every required immutable member before completing.
Only objects have init. Values are assembled with a field block (see construction reference).

Async functions

Async functions declare that they may suspend. The async keyword is part of the signature so callers can see suspension might happen.
  • await is only valid inside async func.
  • await waits for the awaited call; it does not unwrap Result.
  • Standalone task spawning and cancellation are deferred.
The async/await language shape is frozen for v0.1, but the async runtime is deferred. Design your APIs around async today; execution semantics land with the Pulse async runtime.

Return statements

return exits the current function, optionally with a value. The value must be assignment-compatible with the declared return type.

Calling functions

  • Positional arguments for free functions and instance methods.
  • Named arguments are required for object construction (see construction).
  • No default parameter values in v0.1.
  • No overload resolution: each function name is unique in its scope.

Next steps

Control flow

if, match, and how bindings interact with branching.

Functions reference

Complete spec-style reference for every callable form.