[Haskell-cafe] What is the role of $!?

Matthew Brecknell haskell at brecknell.org
Wed Nov 14 21:37:46 EST 2007

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

More information about the Haskell-Cafe mailing list