Book
Result and option
Why errors are values, and when match is required.
Errors as data
Abort is for the impossible. Recoverable failure is data the caller must see. ! packages that failure as a result err. Required match keeps the bad path visible at compile time, matching the discipline used for option some/none arms.
Result
! returns an error payload from the current function and leaves the process running. Any ! in a body makes that function a result: ^ v is ok, ! e is err.
/ std/io
/ std/str
$ checked = (x) {
? x < 0 {
! 99
}
^ x
}
| checked(7) {
$ v {
io.print(str.from_int(v))
}
! e {
io.print(str.from_int(e))
^ 1
}
}Option
Option-shaped functions use ^ value for some and bare ^ for none. Match with $ name {…} and : {…}.
Must handle
Leaving a result or option unhandled is a compile error. There is no silent discard and no separate “try” keyword.