Understanding strictness of ghc output

Olaf Chitil O.Chitil at kent.ac.uk
Tue Jun 22 10:49:12 EDT 2004


Duncan Coutts wrote:

>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.
>  
>
However, standard lazy evaluation will only evaluate a function 
application if the head normal form of the result is needed.
So when  addHeight is computed its result is needed. Hence there is no 
point in writing "h `seq` h" instead of just "h".

This could only make a difference for some form of optimistic evaluator 
that stops in the middle of evaluation on turns the remaining evaluation 
into a closure. But would such an evaluator give the programmer control 
about where exactly it would stop optimistic evaluation?

Olaf

-- 
OLAF CHITIL,
Computing Laboratory, University of Kent, Canterbury, Kent CT2 7NF, UK.
URL: http://www.cs.kent.ac.uk/people/staff/oc/
Tel: +44 (0)1227 824320; Fax: +44 (0)1227 762811



More information about the Glasgow-haskell-users mailing list