<div><div><div><div><div><span class="Apple-style-span" style="font-size: small;">I'm having difficulty to understand the difference between WHNF and HNF.</span></div><div><span class="Apple-style-span" style="font-size: small;"><br>
</span></div><div><span class="Apple-style-span" style="font-size: small;">Is this </span><a href="http://encyclopedia2.thefreedictionary.com/Weak+Head+Normal+Form"><span class="Apple-style-span" style="font-size: small;">explanation</span></a><span class="Apple-style-span" style="font-size: small;"> the correct one? Or is WHNF and HNF equivalent in Haskell land?</span></div>
<div><span class="Apple-style-span" style="font-size: small;"><br></span></div><div><span class="Apple-style-span" style="font-size: small;">The GHC documentation of seq says:</span></div><div><span class="Apple-style-span" style="font-family: '-webkit-sans-serif'; "><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-style: italic;">Evaluates its first argument to head normal form, and then returns its second argument as the result.</span></span></span><span class="Apple-style-span" style="font-size: small;"><span class="Apple-style-span" style="font-style: italic;"><br>
</span></span></div><div><span class="Apple-style-span" style="font-size: small;"><br></span></div><div><span class="Apple-style-span" style="font-family: '-webkit-sans-serif'; "><span class="Apple-style-span" style="font-size: small;">Let's try in GHCi</span></span></div>
<div><span class="Apple-style-span" style="font-family: '-webkit-sans-serif'; "><span class="Apple-style-span" style="font-size: small;"><br></span></span></div><div><span class="Apple-style-span" style="font-family: -webkit-sans-serif;"><div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">*Main> let f = trace "\\x" $ \x -> ((trace "\\y" $ \y -> trace "y" y + trace "x" x) $ trace "2" 2)</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">*Main> f `seq` ()</span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">\x</span></div>
<div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">()</span></div><div><span class="Apple-style-span" style="font-family: 'courier new', monospace;">*Main></span></div><div>
<br></div></div></span></div><div><span class="Apple-style-span" style="font-family: '-webkit-sans-serif'; "><span class="Apple-style-span" style="font-size: small;">That did not evaluate anything inside the body of the first lambda, so according to the article, seq reduces to <span class="Apple-style-span" style="font-style: italic;">weak head normal form</span>, not hnf...</span></span></div>
<div><span class="Apple-style-span" style="font-family: -webkit-sans-serif; font-size: 16px;"><br></span></div><div><span class="Apple-style-span" style="font-family: -webkit-sans-serif; font-size: 16px;"><br></span></div>
</div></div></div></div>