Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're looking for <a href="http://disciple.ouroborus.net/" rel="nofollow noreferrer">Disciple</a>.</p> <p>So there are two kinds of laziness to distinguish in Haskell. There's lazy I/O, which is an abomination and is solved by iteratee libraries (Shameless plug: including my <a href="http://hackage.haskell.org/package/pipes-2.0.0" rel="nofollow noreferrer">pipes</a> library). Then there's laziness in pure computations, which is still open to debate, but I'll try to summarize the key advantages of laziness since you are already familiar with the disadvantage:</p> <p><strong>Laziness is more efficient</strong></p> <p>A simple example is:</p> <pre><code>any = foldr (||) False </code></pre> <p><code>any</code> finds if any value in a list is <code>True</code>. This only evaluates the elements up to the first <code>True</code>, so it doesn't matter if the list is very long.</p> <p>Laziness only computes as much as it has to, meaning that if you chain together two lazy computations, it can actually improve the time complexity of the resulting computation. <a href="https://stackoverflow.com/a/284180/1026598">This Stack Overflow comment</a> gives another good example of this.</p> <p>This is actually the same reason why iteratee libraries are very resource-efficient. They only do as much work as they have to generate results, and this leads to very efficient memory and disk usage with very easy-to-use semantics.</p> <p><strong>Laziness is inherently more composable</strong></p> <p>This is well known by people who have programmed in both strict and functional languages, but I actually inadvertently demonstrated a limited proof of this while working on the <code>pipes</code> library, where the lazy version is the only version that permits a <code>Category</code> instance. Pipes actually work in any monad, including the pure <code>Identity</code> monad, so my proofs translate to pure code as well.</p> <p>This is the true reason why I believe that laziness in general is really the future of programming, however I still think that it's an open question of whether or not Haskell implemented laziness "right".</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload