lazy-evaluation
Why is seq bad?
As far as I know a polymorphic seq function is bad because it weakens free theorems or, in other words, some equalities that are valid without seq are no longer valid with seq. For example, the equality map g (f xs) = f (map g xs) holds for all functions g :: tau -> tau’, … Read more
Accessing a non-static member via Lazy or any lambda expression
You can move it into constructor: private Lazy<int> lazyGetSum; public MyClass() { lazyGetSum = new Lazy<int>(new Func<int>(() => X + Y)); } See @JohnSkeet answer below for more details about the reason of the problem. Accessing a non-static member via Lazy<T> or any lambda expression
Lazy evaluation in Python
The object returned by range() (or xrange() in Python2.x) is known as a lazy iterable. Instead of storing the entire range, [0,1,2,..,9], in memory, the generator stores a definition for (i=0; i<10; i+=1) and computes the next value only when needed (AKA lazy-evaluation). Essentially, a generator allows you to return a list like structure, but … Read more
Do the &= and |= operators for bool short-circuit?
From C++11 5.17 Assignment and compound assignment operators: The behavior of an expression of the form E1 op = E2 is equivalent to E1 = E1 op E2 except that E1 is evaluated only once. However, you’re mixing up logical AND which does short-circuit, and the bitwise AND which never does. The text snippet &&=, … Read more
How does non-strict and lazy differ?
Non-strict and lazy, while informally interchangeable, apply to different domains of discussion. Non-strict refers to semantics: the mathematical meaning of an expression. The world to which non-strict applies has no concept of the running time of a function, memory consumption, or even a computer. It simply talks about what kinds of values in the domain … Read more
Understanding a recursively defined list (fibs in terms of zipWith)
I’ll give a bit of an explanation of how it works internally. First, you must realise that Haskell uses a thing called a thunk for its values. A thunk is basically a value that has not yet been computed yet — think of it as a function of 0 arguments. Whenever Haskell wants to, it … Read more
Is it bad practice to have my getter method change the stored value?
I think it is actually quite a bad practice if your getter methods change the internal state of the object. To achieve the same I would suggest just returning the “N/A”. Generally speaking this internal field might be used in other places (internally) for which you don’t need to use the getter method. So in … Read more
Lazy Evaluation and Time Complexity
In minimum = head . sort, the sort won’t be done fully, because it won’t be done upfront. The sort will only be done as much as needed to produce the very first element, demanded by head. In e.g. mergesort, at first n numbers of the list will be compared pairwise, then the winners will … Read more