// Effect Composition - Combine multiple effects cleanly // // Unlike monad transformers (which have ordering issues), // effects can be freely combined without boilerplate. // Each handler handles its own effect, ignoring others. // // Expected output: // [LOG] Starting computation // Generated: 7 // [LOG] Processing value // [LOG] Done // Result: 14 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 {}