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

Jonathan Cast jonathanccast at fastmail.fm
Wed Nov 14 20:50:07 EST 2007


On 14 Nov 2007, at 4:32 PM, Shachaf Ben-Kiki wrote:

> On Nov 14, 2007 4:27 PM, Justin Bailey <jgbailey at gmail.com> wrote:
>> It's:
>>
>>   f $! x = x `seq` f x
>>
>> That is, the argument to the right of $! is forced to evaluate, and
>> then that value is passed to the function on the left. The function
>> itself is not strictly evaluated (i.e., f x) I don't believe.
>
> Unless you mean f -- which I still don't think would do much -- it
> wouldn't make sense to evaluate (f x) strictly.

Right.  (f x) evaluates f and then applies it to x.  (f $! x)  
evaluates x, evaluates f, and then applies f to x.

jcc



More information about the Haskell-Cafe mailing list