3 ms·
The article explains that.
by cosarara 7y ago
The article explains that.
- runeks 7y agoNo, laziness has nothing to do with iterating over the file multiple times. If you perform three separate operations on the same file (as the first, naive version does), you will iterate over the file three times regardless of the evaluation strategy. The high memory usage is related to the lazy evaluation of the arguments to the “go” function. When these arguments are evaluated strictly, iterating over the file three times would increase running time by a factor of three, but the memory usage would still be low (ie. roughly proportional to the file size).
- cosarara 7y agoWhat I quoted is talking about the 2nd version of the code, that tries to count without iterating three times and then encounters a laziness problem. The first version iterates three times and the reason it takes long has nothing to do with lazyness, we agree on that.
- runeks 7y agoI see your point now. My mistake. In order to avoid iterating over the file three times, he writes the second version, which does require understanding laziness (in order to avoid high memory usage). I stand corrected.