Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There's a difference between normal order evaluation an lazy evaluation (as in Haskell).</p> <pre><code>square x = x * x </code></pre> <p>Evaluating the following expression...</p> <pre><code>square (square (square 2)) </code></pre> <p>... with eager evaluation:</p> <pre><code>&gt; square (square (2 * 2)) &gt; square (square 4) &gt; square (4 * 4) &gt; square 16 &gt; 16 * 16 &gt; 256 </code></pre> <p>... with normal order evaluation:</p> <pre><code>&gt; (square (square 2)) * (square (square 2)) &gt; ((square 2) * (square 2)) * (square (square 2)) &gt; ((2 * 2) * (square 2)) * (square (square 2)) &gt; (4 * (square 2)) * (square (square 2)) &gt; (4 * (2 * 2)) * (square (square 2)) &gt; (4 * 4) * (square (square 2)) &gt; 16 * (square (square 2)) &gt; ... &gt; 256 </code></pre> <p>... with lazy evaluation:</p> <pre><code>&gt; (square (square 2)) * (square (square 2)) &gt; ((square 2) * (square 2)) * ((square 2) * (square 2)) &gt; ((2 * 2) * (2 * 2)) * ((2 * 2) * (2 * 2)) &gt; (4 * 4) * (4 * 4) &gt; 16 * 16 &gt; 256 </code></pre> <p>That's because lazy evaluation looks at the syntax tree and does tree-transformations...</p> <pre><code>square (square (square 2)) || \/ * / \ \ / square (square 2) || \/ * / \ \ / * / \ \ / square 2 || \/ * / \ \ / * / \ \ / * / \ \ / 2 </code></pre> <p>... whereas normal order evaluation only does textual expansions.</p> <p>That's why we, when using lazy evaluation, get more powerful (evaluation terminates more often then other strategies) while the performance is equivalent to eager evaluation (at least in O-notation).</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