title: How does seq force functions?
body: <h3>Background</h3>
  
  <p>This question arises from a challenge Brent Yorgey posed at OPLSS: write a function <code>f :: (Int -&gt; Int) -&gt; Bool</code> that distinguishes <code>f undefined</code> from <code>f (\x -&gt; undefined)</code>. All of our answers either used <code>seq</code> or something like bang patterns that desugar into <code>seq</code>. For example:</p>
  
  <pre><code>f :: (Int -&gt; Int) -&gt; Bool
  f g = g `seq` True
  
  *Main&gt; f undefined
  *** Exception: Prelude.undefined
  *Main&gt; f (\x -&gt; undefined)
  True
  </code></pre>
  
  <p>The <a href="http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/SeqMagic">GHC commentary on <code>seq</code></a> says that </p>
  
  <pre><code>e1 `seq` e2 
  </code></pre>
  
  <p>used to desugar into </p>
  
  <pre><code>case e1 of { _ -&gt; e2 }
  </code></pre>
  
  <p>so I tried desugaring manually. It didn't work:</p>
  
  <pre><code>f' g = case g of { _ -&gt; True }
  
  *Main&gt; f' undefined
  True
  *Main&gt; f' (\x -&gt; undefined)
  True
  </code></pre>
  
  <h3>Question</h3>
  
  <p>Does this behavior depend on the more complex <code>seq</code> described <a href="http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/SeqMagic#Abetterway">at the end of the commentary</a>, and if so, how does it work? Could such an <code>f</code> be written without these primitives?</p>
  
  <pre><code>x  `seq` e2 ==&gt; case seq# x RW of (# x, _ #) -&gt; e2    -- Note shadowing!
  e1 `seq` e2 ==&gt; case seq# x RW of (# _, _ #) -&gt; e2
  </code></pre>