[Haskell-cafe] Is id strict?

Ian Lynagh igloo at earth.li
Sun Jul 30 06:08:19 EDT 2006

On Sun, Jul 30, 2006 at 09:44:25AM +0100, David House wrote:
> 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.

If the value of (id x) is demanded then the value of x will always be
demanded. Therefore id is strict in its first argument.

If x is _|_ then this implies the result of f x will also be _|_, as per
the "f is strict => f _|_ = _|_" half of your 1).
"f _|_ = _|_ => f is strict" is not true, e.g. for f _ = f 'a'.

In place of your 2), I would say
    (f x0 .. xn) is strict in xi if demanding the value of (f x0 .. xn)
requires demanding the value of xi.

("demanding the value" in the above means evaluating to weak head normal

Hope that helps.


More information about the Haskell-Cafe mailing list