How to reduce memory usage in a Haskell app?

Lists are not the best datastructure for this type of code (with lots of (++), and (last)). You lose a lot of time constucting and deconstructing lists. I’d use Data.Sequence or arrays, as in C versions. There is no chance for thunks of makeu0 to be garbage-collected, since you need to retain all of them … Read more

Do Immutable.js or Lazy.js perform short-cut fusion?

I’m the author of Immutable.js (and a fan of Lazy.js). Does Lazy.js and Immutable.js’s Seq use short-cut fusion? No, not exactly. But they do remove intermediate representation of operation results. Short-cut fusion is a code compilation/transpilation technique. Your example is a good one: var a = [1,2,3,4,5].map(square).map(increment); Transpiled: var a = [1,2,3,4,5].map(compose(square, increment)); Lazy.js and … Read more

Haskell: how to detect “lazy memory leaks”

The main method for detecting memory leaks is heap profiling. Specifically, you’re looking for unexpected growth in the amount of resident (mostly heap) memory, either the maximum residency in the +RTS -s statistics output, or — more reliably — a characteristic “pyramid” shape over time in heap profile output generated with the +RTS -h<x> flags … Read more

Does Java have lazy evaluation?

Well, as far as the language is concerned – yes, both functions are called. If you rewrote the function to this: public boolean isTrue() { return isBTrue() || isATrue(); } then the second function will not be called, if the first is true. But this is short-circuit evaluation, not lazy evaluation. Lazy evaluation case would … Read more