Understanding strictness of ghc output

Simon Marlow simonmar at microsoft.com
Tue Jun 22 11:59:34 EDT 2004

On 22 June 2004 15:59, Malcolm Wallace wrote:

> "Simon Marlow" <simonmar at microsoft.com> writes:
>> Nope.  You can't return something without evaluating it to head
>> normal form in Haskell.  Every value that is "returned" is a value,
>> never a thunk.  If you want to return something unevaluated, you
>> have to wrap it in a constructor.
> Actually, there are two possible strategies for who evaluates a thunk
> to head normal form.  The caller or the callee.  GHC says that the
> callee always evaluates to HNF before returning the value.  But the
> language does not force this implementation choice.  It is equally
> possible for an implementation of the function to return a thunk and
> for the caller to evaluate it if necessary.  Both strategies give the
> same result semantically, since if the value in question is demanded,
> it gets evaluated.

If a function is called, then the result has been demanded.  There are
no situations in which a function has been called but the caller will
accept a thunk as the result without further evaluating it.

So what is the advantage of returning a possibly-unevaluated result?
The caller will definitely have to evaluate it, so every eval will need
to loop until the value is in HNF.

And what about updates?


More information about the Glasgow-haskell-users mailing list