Hacker News new | ask | show | jobs
by JoshTriplett 3712 days ago
Haskell's laziness can also be a notorious source of "space leaks": an algorithm that appears O(1) in space, such as summing up a list of numbers, can actually use O(n) space by accumulating unevaluated invocations of (+) in memory. With more complex data structures, the proportion of expected memory usage to actual memory usage can get even worse.

In larger Haskell programs, I've found that the most challenging issue to debug: "why does my program use way too much memory?".

1 comments

Practically, the way to go here is: make your data structures strict (with "!") and make your control structures lazy.

So, don't create a list of numbers if you intend to sum it, use a non- lazy data structure.

The trick is that Haskell's common default structures are lazy.