As part of my efforts to investigate space leaks, I ended up at the fold_lookahead function, which I rewrote as below. I offer this as an entirely separate patch because there are good reasons you might want to not merge it. Advantages:
Rewrite fold_lookahead to avoid using the stack and improve time comp…
The patch looks sensible to me. This codebase is very very very old you know :)
I was impressed just quite how many foldrs I found in the code base 😄.
I guess I was going through a foldr-happy phase.