Skip to content

26 · Algebraic Effects

Prefix lexical handlers

with handler_value { body } evaluates and installs the handler before the body. It uses the same semantics as handle body with handler_value. Nested scopes restore the enclosing handler, and returns and cleanup retain their lexical boundaries. The value must be a proven Handler.

On this page

with handler_value { body } evaluates and installs the handler before the body. It uses the same semantics as handle body with handler_value. Nested scopes restore the enclosing handler, and returns and cleanup retain their lexical boundaries. The value must be a proven Handler.

Complete example

Prefix lexical handlers.

21-lexical-handlers.zolo
Playground
// Prefix handler installation keeps the interpretation next to its scope.

// expected:

// memory

// inner

// memory


effect Config {
    fn read() -> str
}

fn load() with Config -> str = perform Config::read()

let memory = handler {
    Config::read() => "memory",
}

let inner = handler {
    Config::read() => "inner",
}

print(with memory { load() })

let nested = with memory {
    let answer = with inner { load() }
    answer
}
print(nested)
print(with memory { load() })

Rules and behavior

Handlers and resource scopes · Documentation

From a checkout of the repository:

zolo examples/features/25-effects/21-lexical-handlers.zolo

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br