akh
akh copied to clipboard
Late and Rec
Bennu currently defines two parser late and rec that would be useful as a more general solution for Akh monads
Late resolves the content of function only when a computation is actually run.
var a;
// `a` is not defined yet but we don't care since it is resolved when `c` is run
var c = M.late(\-> a).map(+, 10);
a = M.of 3;
run c; // 13
Rec allows references to itself and is defined using late
rec = \def -> {
var value = def <| late\->value;
return value;
};
var c = rec \ self -> M.get.chain(\x -> x > 10 : M.of x : M.modify(+, 1).concat(self))