Effects
Effects and handlers
Use effect, perform, handle, and resume as part of normal Musi code.
What
Effects are built into the language as part of normal flow control: you define an effect, perform it, and handle it at a boundary.
Why
This model separates “what happened” from “how to handle it,” which keeps business logic clearer as projects grow.
let Console := effect {
let readln () : String;
};How
Define one effect family, perform operations, and add handlers for policy (logging, fallback, default values, reporting).
perform Console.readln();When
Use effects for cross-cutting concerns: resource usage, command routing, telemetry, and deferred behavior.
handle perform Console.readln() with Console of (
| value => value
| readln(k) => resume "ok"
);Analogy
Comparable to middleware stacks in web frameworks, but in expression-level form.
Try it
Read all three snippets end-to-end, then continue to Types and generics.
Continue to Types and generics.
github.com/musi-lang/musi
musi-lang.com