import Std.Fail
Effects
Fail
effect Fail =
fail: fn Unit -> Never
Functions
try
try (f: a can Fail, e): Maybe a can e
on_fail
on_fail (f: a can Fail, e) (default: a can e): a can e
assert
assert (cond: Bool): Unit can Fail
Fails if cond is false
Note that this is the inverse of fail_if
fail_if
fail_if (cond: Bool): Unit can Fail
Fails if cond is true
Note that this is the inverse of assert
panic_on_fail
panic_on_fail (f: a can Fail, e): a can Panic, e
Asserts the operation cannot fail. Panics at runtime if it does.
abort_on_fail
abort_on_fail (f: a can Fail, e): a can e
Similar to panic_on_fail but aborts the entire process instead of panicking. Generally this should be avoided when possible unless you can guarantee a panic will not occur and cannot have the Panic effect in a function.
or_panic
or_panic (f: a can Fail, e) (message: String): a can Panic, e
Panics on failure with the given error message
ignore_fail
ignore_fail (f: a can Fail, e): Unit can e
Ignores a Fail effect, discarding it and returning Unit
retry_until_success
retry_until_success (f: a can Fail, e): a can e
Retry a function until it succeeds (doesn’t call fail). This should be used with functions using a Fail effect along with other effects. Otherwise, it will loop forever.
get_input () -> string can IO = ...
parse (s: string) -> u32 can Fail = ...
number = retry_until_success $$
input = get_input ()
parse input