Custom Effects
Define your own effects and propagate them through function signatures.
Custom Effects
Sounio lets you declare your own effects to model domain-specific side effects.
Declaring an Effect
An effect is a named set of operations:
effect Fail {
fn fail(msg: string) -> !
}
Using an Effect
Call effect operations like normal functions, and declare the effect in the signature:
fn might_fail() with Fail {
Fail.fail("something went wrong")
}
Propagating Requirements
Callers must also declare the effect:
fn main() with Fail {
might_fail()
}
If you forget, the compiler reports an error:
fn main() {
might_fail() // ERROR: Fail effect not declared / handled
}
Spec Note: Effect Handlers
The language design includes algebraic effect handlers (resumption, interpretation, etc.). If you see handle / resume syntax in older docs, treat it as spec-level unless the current compiler mode explicitly supports it.