Files
lux/examples/showcase/effect_composition.lux
2026-02-17 06:52:44 -05:00

27 lines
564 B
Plaintext

effect Log {
fn log(msg: String): Unit
}
fn computation(): Int with {Log, Random} = {
Log.log("Starting computation")
let x = Random.int(1, 10)
Log.log("Processing value")
let result = x * 2
Log.log("Done")
result
}
handler consoleLog: Log {
fn log(msg) = Console.print("[LOG] " + msg)
}
fn main(): Unit with {Console} = {
let result = run computation() with {
Log = consoleLog,
}
Console.print("Generated: " + toString(result / 2))
Console.print("Result: " + toString(result))
}
let output = run main() with {}