4 ms·
You don't have to get into the intricacies of laziness when you are learning the language IMHO.
by tirumaraiselvan 7y ago
You don't have to get into the intricacies of laziness when you are learning the language IMHO.
- cosarara 7y agoUnless you are trying to write `wc` without iterating the file 3 times, it seems.
- runeks 7y agoHow is that related to laziness?
- cosarara 7y agoThe 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.
- otabdeveloper4 7y agoYes, if you want your shells scripts to consume 3 gigabytes of memory.