
15 Nov
2007
15 Nov
'07
2:37 a.m.
Jonathan Cast:
Right. (f x) evaluates f and then applies it to x. (f $! x) evaluates x, evaluates f, and then applies f to x.
True, though I'd like to chip in a small refinement: When evaluated, (f x) evaluates f as far as its top-level lambda, then applies it to x, and then continues to evaluate (only) to the extent demanded by its consumers. When evaluated, (f $! x) evaluates x to weak-head-normal-form (WHNF), and then evaluates (f x). I think the initial "when evaluated" is the most important part to remember when thinking about seq and lazy evaluation. It's the reason why (x `seq` x) is identical to x, as mentioned by someone else in this thread.