[Haskell-cafe] Re: Is id strict?
duncan.coutts at worc.ox.ac.uk
Sun Jul 30 09:25:18 EDT 2006
On Sun, 2006-07-30 at 13:22 +0100, Jón Fairbairn wrote:
> Duncan Coutts <duncan.coutts at worc.ox.ac.uk> writes:
> > On Sun, 2006-07-30 at 10:56 +0100, Jón Fairbairn wrote:
> > > "David House" <dmhouse at gmail.com> writes:
> > > > 1) f is strict iff f _|_ = _|_.
> > > > 2) f is strict iff it forces evaluation of its arguments.
> > 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.
> Which is pretty much my point. Use a definition of "strict"
> that doesn't depend on anything but denotations (or Böhm
Yes, for being precise a denotational approach is simpler.
However for an intuition about how strictness affects evaluation order
and space and performance behaviour I find that 2) is quite a helpful
way to look at things. It allows you to look at a function and ask: if I
demand the result in WHNF (which I know will happen if the function is
called at runtime) what demand will that place on other expressions,
variables and arguments.
The discussion on #haskell went on to conclude that we need better tools
for showing us the inferred strictness of functions we write (eg by
getting the compiler to tell us). It was also noted that many Haskell
programmers, especially beginners have very little intuition about
strictness and so can't get themselves out of troubles caused by too
much or to little strictness, like performance problems, memory leaks
and exceptions slipping past exception handlers.
More information about the Haskell-Cafe