(module loop_nested_in_lambda (fn make_adder (doc "Iter it.1 — a loop inside a lambda body (lambda-boundary analogue). Iter it.2: the returned closure is loop-bearing, so its arrow carries !Diverge (DD-4 lam boundary); make_adder's return type reflects that. make_adder's own body does not contain the loop (it stops at the lam edge), so make_adder itself stays effect-free.") (type (fn-type (params (con Int)) (ret (fn-type (params (con Int)) (ret (con Int)) (effects Diverge))))) (params base) (body (lam (params (typed x (con Int))) (ret (con Int)) (effects Diverge) (body (loop ((var acc (con Int) base) (var k (con Int) 0)) (if (app == k x) acc (recur (app + acc 1) (app + k 1)))))))))