Understanding strictness of ghc output

Duncan Coutts duncan.coutts at worcester.oxford.ac.uk
Tue Jun 22 10:10:36 EDT 2004

On Tue, 2004-06-22 at 14:17, Tomasz Zielonka wrote:
> On Tue, Jun 22, 2004 at 01:52:44PM +0100, Malcolm Wallace wrote:
> > 
> > Same again.  Try
> >    addHeight h  E        = h `seq` h
> > 
> > which, although it looks bizarre, actually forces the evaluation of h,
> > whilst simply returning it does not.
> 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.

I think a better intuition is that "h is forced before h is *returned*".
You can return a value without that value being forced to head normal
form. In fact this is the ordinary case. Values are only 'forced' when
you pattern match on them (or if you use seq), and even then only when
the result of the pattern match is used.


More information about the Glasgow-haskell-users mailing list