error
Explicit error handling as part of the AST structure. Errors are values that can be caught, recovered from, and accumulated rather than thrown as exceptions.
Included on the default interpreter.
const app = mvfm(prelude, error);
const prog = app({ x: "number" }, ($) => {
const risky = $.cond($.gt($.input.x, 10))
.t($.input.x)
.f($.fail("too small"));
return $.try(risky).catch((err) =>
$.concat("recovered: ", err)
);
});
await fold(defaults(app), injectInput(prog, { x: 3 })); Ctrl+Enter