<div dir="ltr"><div>I've asked a question on stackoverflow, which is basically a typical question about folds and space leaks due to laziness, in this case complicated by a Maybe and foldM:</div><div><br></div><a href="https://stackoverflow.com/questions/67559724/constant-space-short-circuiting-foldm-over-maybe">https://stackoverflow.com/questions/67559724/constant-space-short-circuiting-foldm-over-maybe</a><br><div><br></div><div>That's getting answered, but when I saw the answers, I noticed people are using a fairly mechanical process, basically going through how the code would be evaluated step by step, to determine whether there's a space leak or not. And that tends to be the case for most of these questions.</div><div><br></div><div>It's complicated enough that it's hard to keep track of in my head, but I thought to myself, wouldn't a computer be able to check this much more quickly and reliably? </div><div><br></div><div>There doesn't seem to be much human intuition required here, just a lot of pen and paper work to try to determine whether you've got an unevaluated thunk hanging around at the end of an iteration.</div><div><br></div><div>I understand doing this analysis for the whole program may be impossible, but we can certainly do it for parts, because flesh and blood human beings can do it for stackoverflow answers. </div><div><br></div><div>Is there anything I can get that helps me identify space leaks like this at compile time (that is, pre-runtime)? Either from GHC or from another tool? Or do we just have to rely on squishy humans to do this as compile time and our only automated tools have to be delayed til runtime? </div><div><br></div><div>Thanks,</div><div>Clinton</div></div>