// Custom Logging with Effects // // This demonstrates how effects let you abstract side effects. // The same code can be run with different logging implementations. // // Expected output: // [INFO] Starting computation // [DEBUG] x = 10 // [INFO] Processing // [DEBUG] result = 20 // Final: 20 effect Log { fn info(msg: String): Unit fn debug(msg: String): Unit } fn computation(): Int with {Log} = { Log.info("Starting computation") let x = 10 Log.debug("x = " + toString(x)) Log.info("Processing") let result = x * 2 Log.debug("result = " + toString(result)) result } handler consoleLogger: Log { fn info(msg) = { Console.print("[INFO] " + msg) resume(()) } fn debug(msg) = { Console.print("[DEBUG] " + msg) resume(()) } } fn main(): Unit with {Console} = { let result = run computation() with { Log = consoleLogger } Console.print("Final: " + toString(result)) } let output = run main() with {}