Functions
Defining functions, return values, and effect annotations.
Functions
Functions are still the clearest place where Sounio looks like itself: they combine ordinary typed parameters and returns with explicit effect tracking. This page focuses on what that means in the current public contract.
Current contract
- Functions are declared with
fnand may return a value using the final expression in the body. - Side effects are modeled explicitly with
with ...in the function signature. - Simple generic and method-shaped patterns exist in the language design, but the best public examples are still the ones backed by current fixtures and by the checked artifact.
Function shapes worth teaching
fn add(a: i32, b: i32) -> i32 {
a + b
}
fn log(msg: string) with IO {
println(msg)
}
Where this is implemented
self-hosted/parser/items.sioandself-hosted/parser/types.sioare central for declaration parsing.self-hosted/check/types.sio,self-hosted/check/infer.sio, andself-hosted/check/effects.siocover function typing and effect requirements.self-hosted/check/traits.sioandself-hosted/check/specialization.sioare useful when you are tracing more advanced callable surfaces.
Common documentation mistakes to avoid
- Do not present function signatures as pure type-only syntax; in Sounio the effect clause is part of the practical API contract.
- Do not assume that every advanced callable feature mentioned in old docs is equally stable in the checked artifact.
- For public docs, keep examples small, explicit, and easy to validate with
souc check.