// Test error handling patterns from the documentation io.out "=== Testing Error Handling Patterns ==="; // Basic Result usage divide : x y -> when y is 0 then Err "Division by zero" _ then Ok (x / y); handleDivision : x y -> when (divide x y) is Ok result then result Err message then 0; io.out "Division results:"; io.out (handleDivision 10 2); // Should be 5 io.out (handleDivision 10 0); // Should print error and return 0 // Validation patterns validateAge : age -> when (validate.type "Int" age) is false then Err "Age must be an integer" true then when (validate.range 0 150 age) is false then Err "Age must be between 0 and 150" true then Ok age; io.out ""; io.out "Validation results:"; io.out (validateAge 25); // Should be Ok 25 io.out (validateAge 200); // Should be Err message io.out (validateAge "not a number"); // Should be Err message // Simple assertion example io.out ""; io.out "Assertion example:"; assert (2 + 2 = 4) "Math works"; io.out "Assertion passed!"; // Debug example io.out ""; io.out "Debug example:"; debug.print "Testing debug output" 42; io.out ""; io.out "Error handling tests completed!";