lazy-evaluation
Non-Trivial Lazy Evaluation
Have you ever written an AI? Isn’t it annoying that you have to thread pruning information (e.g. maximum depth, the minimum cost of an adjacent branch, or other such information) through the tree traversal function? This means you have to write a new tree traversal every time you want to improve your AI. That’s dumb. … Read more
How to force evaluation in Haskell?
Answer originally given by user ysdx on programmers: Indeed you version will not benchmark your algorithm. As r is not used it will not be evaluated at all. You should be able to do it with DeepSeq: benchmark :: [String] -> IO Integer benchmark inputList = do start <- getCPUTime let r = foo inputList … Read more
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
What is the opposite of lazy loading?
The oposite term for lazy loading is eager loading. Eager loading is essentially computing the tasks when you ask for it. Lazy Loading is when you only do the computation when it is required.
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
Pass parameters to constructor, when initializing a lazy instance
Try this: Lazy<myClass> myLazy = new Lazy<myClass>(() => new myClass(InstanceName)); Remember that the expression is evaluated lazily, so if you change the value of the variable InstanceName before the constructor is called it might not do what you expect.
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
Swift: implement a protocol variable as a lazy var?
Citing the Language Guide – Properties – Lazy Stored Properties [emphasis mine]: A lazy stored property is a property whose initial value is not calculated until the first time it is used. I.e., the value is mutated upon first usage. Since foo has been blueprinted in the Foo protocol as get, implicitly nonmutating get, the … Read more