Understanding strictness of ghc output

Carsten Schultz carsten at codimi.de
Tue Jun 22 09:45:22 EDT 2004


On Tue, Jun 22, 2004 at 02:37:38PM +0100, Malcolm Wallace wrote:
> "Simon Peyton-Jones" <simonpj at microsoft.com> writes:
> 
> > | That contradicts my intution for seq. I would read it as "h is forced
> > | before h is forced", and I would think that (h `seq` h) is equivalent
> > | to h.
> > | 
> > | Were I am wrong?
> > 
> > You're not wrong -- Malcolm is.  The function is certainly strict in h,
> > and GHC finds it.  
> 
> Well, it is certainly the case that in a denotational sense the
> function is strict in h, because if h is bottom, the result is bottom.
> 
> But my operational understanding is that h is a projection, that is,
> it is passed from argument to result unmodified.  The demand on h
> comes from the caller of the present function, which may or may not
> be strict in that result.  Thus, the function code itself here does
> not force the evaluation of h.

The point is that, because the function is strict, its implementation
may force the evaluation of h, if it so chooses.  This is up to the
compiler, and as Simon pointed out, it actually does force h when
compiling with optimization.

Greetings,

Carsten

-- 
Carsten Schultz (2:38, 33:47), FB Mathematik, FU Berlin
http://carsten.codimi.de/
PGP/GPG key on the pgp.net key servers, 
fingerprint on my home page.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/glasgow-haskell-users/attachments/20040622/31695155/attachment.bin


More information about the Glasgow-haskell-users mailing list