Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong><code>seq</code> and <code>($!)</code> <a href="http://users.aber.ac.uk/afc/stricthaskell.html#seq" rel="nofollow noreferrer">only evaluate</a> enough to check that something is not bottom.</strong></p> <p>The following program will only print "there".</p> <pre><code>main = print "hi " `seq` print "there" </code></pre> <p>For those unfamiliar with Haskell, Haskell is non-strict in general, meaning that an argument to a function is only evaluated if it is needed.</p> <p>For example, the following prints "ignored" and terminates with success.</p> <pre><code>main = foo (error "explode!") where foo _ = print "ignored" </code></pre> <p><code>seq</code> is known to change that behavior by evaluating to bottom if its first argument is bottom.</p> <p>For example:</p> <pre><code>main = error "first" `seq` print "impossible to print" </code></pre> <p>... or equivalently, without infix ...</p> <pre><code>main = seq (error "first") (print "impossible to print") </code></pre> <p>... will blow up with an error on "first". It will never print "impossible to print".</p> <p>So it might be a little surprising that even though <code>seq</code> is strict, it won't evaluate something the way eager languages evaluate. In particular, it won't try to force all the positive integers in the following program. Instead, it will check that <code>[1..]</code> isn't bottom (which can be found immediately), print "done", and exit.</p> <pre><code>main = [1..] `seq` print "done" </code></pre>
 

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