; Iter 15c — empirical stress test for std_list's folds. ; Builds a 1000-element list [1000, 999, ..., 1] and folds it with ; both fold_left (tail-marked, should run in constant stack via ; `musttail call` lowering) and fold_right (constructor-blocked, ; runs at ~1000-deep stack — well within an 8MB Linux stack budget). ; Expected stdout: two lines, each `500500` (sum 1..1000 = 500500). (module std_list_stress (import std_list) (fn build (doc "Build [n, n-1, ..., 1] :: List Int via Cons recursion. Constructor-blocked; not tail.") (type (fn-type (params (own (con Int))) (ret (own (con List (con Int)))))) (params n) (body (if (app eq n 0) (term-ctor List Nil) (term-ctor List Cons n (app build (app - n 1)))))) (fn add (doc "Binary +. Used as the fold accumulator op for both fold_left and fold_right.") (type (fn-type (params (own (con Int)) (own (con Int))) (ret (own (con Int))))) (params a b) (body (app + a b))) (fn main (doc "Build a 1000-element list, fold it both ways, print both sums (each 500500).") (type (fn-type (params) (ret (own (con Unit))) (effects IO))) (params) (body (seq (seq (app print (app List.fold_left add 0 (app build 1000))) (do io/print_str "\n")) (seq (app print (app List.fold_right add 0 (app build 1000))) (do io/print_str "\n"))))))