// Demonstrating resumable effect handlers in Lux // // Handlers can use `resume(value)` to return a value to the effect call site // and continue the computation. This enables powerful control flow patterns. // // Expected output: // [INFO] Starting computation // [DEBUG] Intermediate result: 10 // [INFO] Computation complete // Final result: 20 // Define a custom logging effect effect Logger { fn log(level: String, msg: String): Unit fn getLogLevel(): String } // A function that uses the Logger effect fn compute(): Int with {Logger} = { Logger.log("INFO", "Starting computation") let x = 10 Logger.log("DEBUG", "Intermediate result: " + toString(x)) let result = x * 2 Logger.log("INFO", "Computation complete") result } // A handler that prints logs with brackets and resumes with Unit handler prettyLogger: Logger { fn log(level, msg) = { Console.print("[" + level + "] " + msg) resume(()) } fn getLogLevel() = resume("DEBUG") } // Main function fn main(): Unit with {Console} = { let result = run compute() with { Logger = prettyLogger } Console.print("Final result: " + toString(result)) } let output = run main() with {}