Effects

Make side effects explicit with `with IO`, `with Panic`, `with Async`, and custom effects.

Effects

Sounio tracks side effects in function signatures using an explicit with ... clause.

Pure vs Effectful

fn double(x: i32) -> i32 {
    x * 2
}

fn greet() with IO {
    println("Hello")
}

Built-in Effects (Common)

  • IO: console + filesystem + external I/O
  • Panic: operations that may trap/abort (e.g., division by zero, indexing out of bounds)
  • Async: async/await and concurrency primitives
  • Alloc: heap allocation
  • Mut: mutable state (where applicable)
  • GPU: GPU kernels / device operations (feature-dependent)

Effect Errors

If you call an effectful function from a pure function, the compiler reports an error until you:

  • add the required effect(s) to the caller’s signature, or
  • refactor so the effect stays at the boundary (recommended).

Spec vs Implementation

The specification’s goal is “effects are explicit everywhere.” Some built-in operations may currently be treated more leniently than user-defined effectful functions, depending on compiler mode and feature flags.

Next