[Haskell-cafe] WHNF versus HNF (was: Optimizing unamb by determining the "state" of a thunk?)

Marcin Kosiba marcin.kosiba at gmail.com
Wed Apr 22 18:27:19 EDT 2009


On Wednesday 22 April 2009, Peter Verswyvelen wrote:
> I'm having difficulty to understand the difference between WHNF and HNF.
>
> Is this
> explanation<http://encyclopedia2.thefreedictionary.com/Weak+Head+Normal+For
>m> the
> correct one? Or is WHNF and HNF equivalent in Haskell land?
>
> The GHC documentation of seq says:
> Evaluates its first argument to head normal form, and then returns its
> second argument as the result.
>
> Let's try in GHCi
>
> *Main> let f = trace "\\x" $ \x -> ((trace "\\y" $ \y -> trace "y" y +
> trace "x" x) $ trace "2" 2)
> *Main> f `seq` ()
> \x
> ()
> *Main>
>
> That did not evaluate anything inside the body of the first lambda, so
> according to the article, seq reduces to weak head normal form, not hnf...
Hi,
 Try:

Prelude Debug.Trace> (f 0) `seq` ()
\x
\y
y
2
x
()

--
Thanks!
	Marcin Kosiba
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20090423/7184fb81/attachment.bin


More information about the Haskell-Cafe mailing list