Closed ivenmarquardt closed 3 years ago
The following program should be lazy by stopping the evaluation after the first iteration, but instead it causes a stack overflow:
A.foldk( fun(x => y => Cont(fun( k => x + y > 10000 ? x : thunk(() => k(x + y), "() => Number"), "(Number => Number) => Number")), "Number => Number => Cont<Number, Number>")) (0) (Array(1e5).fill(1));
thunks are now evaluated a single layer deep in some cases, not all the way down to weak head normal form. This allows foldk to be stack-safe by using the strictRec trampoline.
thunk
foldk
strictRec
The following program should be lazy by stopping the evaluation after the first iteration, but instead it causes a stack overflow: