fn safeDivide(a: Int, b: Int): Int with {Fail} = if b == 0 then Fail.fail("Division by zero") else a / b

fn validatePositive(n: Int): Int with {Fail} = if n < 0 then Fail.fail("Negative number not allowed") else n

fn compute(input: Int): Int with {Console, Fail} = {
    Console.print("Starting computation...")
    Console.print("Step 1: validating input")
    let validated = validatePositive(input)
    Console.print("Step 2: processing")
    let result = safeDivide(validated * 2, 1)
    Console.print("Result: " + toString(result))
    result
}

fn main(): Unit with {Console} = {
    let result = run compute(21) with {}
    Console.print("Done!")
}

let output = run main() with {}
