[Haskell-cafe] Re: Is id strict?
duncan.coutts at worc.ox.ac.uk
Sun Jul 30 08:08:53 EDT 2006
On Sun, 2006-07-30 at 10:56 +0100, Jón Fairbairn wrote:
> "David House" <dmhouse at gmail.com> writes:
> > Hi all.
> > I've seen two definitions of a 'strict function', which I'm trying to
> > unite in my mind:
> > 1) f is strict iff f _|_ = _|_.
> > 2) f is strict iff it forces evaluation of its arguments.
> > There is a large sticking point that in my minds seems to fit (1) but
> > not (2): id. Clearly, id undefined is undefined, but I also don't
> > think id forces evaluation of its argument. There was a
> > mini-discussion concerning this topic last night on #haskell, but if
> > there was a consensus conclusion, it passed me by.
> > Thanks in advance.
> In (2), you have to be evaluating f on an argument before f
> can force the argument. If you evaluate id x, you
> necessarily evaluate x. I don't think (2) is a very good
> definition, since I don't know what "forces" means here.
Surely it just means evaluate to weak head normal form?
Definition 2) relies on following a certain evaluation strategy: that
operationally, functions always return results in weak head normal form.
GHC follows this strategy. It's possibly to imagine returning thunks and
then getting the caller to force the evaluation to WHNF.
So under the latter model, 'id' would operationally do nothing. It would
not force its argument. Under the more sensible model 'id' does force
its argument to WHNF before returning.
More information about the Haskell-Cafe