-
-
Notifications
You must be signed in to change notification settings - Fork 0
Failure And Propagation
fn load(path: Str) -> Result[Str, Str] {
let text = readFile(path) ?
Ok(text)
}
Status: Result, Option, exhaustive matching, postfix ?, typed early return, and panic execute
in the interpreter. Pudu does not use exceptions for expected failure.
type Result[T, E] = Ok(T) | Err(E)
type Option[T] = Some(T) | None
Operations that can fail recoverably return a carrier. Standard-library effects generally use
Result and preserve the operating-system message as text.
? reads its carrier from the enclosing function return type.
fn first(value: Option[Int]) -> Option[Int] {
let held = value ?
Some(held)
}
In a Result function, Err(error)? returns the same Err(error) and requires the exact declared
failure type. Failure conversion is not implemented. In an Option function, None? returns
None. A target with the wrong carrier is a type error; ? does not catch panic.
W3003 identifies a match that merely rebuilds the same failure carrier and can be written with
?. A branch that transforms the error or changes the carrier is a real decision and is not
warned.
| Need | Form |
|---|---|
| Forward the same failure | ? |
| Bind one success and exit otherwise | let PATTERN = value else { ... } |
| Run one success branch with optional fallback | if let PATTERN = value { ... } |
| Transform or recover from several cases | match |
panic represents a violated invariant, not a recoverable domain outcome. Compile-time effect
restrictions, runtime diagnostics, and ordinary failure carriers remain separate.
- Modules And Imports
- Values, Bindings, And Blocks
- Types And Inference
- Records, Sums, And Tuples
- Functions Generics And Traits
- Pattern Language
- Control Flow And Patterns
- Iteration And Loops
- Failure And Propagation
- Numbers And Collections
- Sets Maps And Sequences
- Keyed Structures
- Trees And Hierarchies
- Standard Library
- Output Formatting And Testing
- Tasks And Scopes
- Compile-Time Evaluation
- Typed Macros
- References And Unsafe
- Worked Programs