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

David Fox ddssff at gmail.com
Mon Dec 10 01:15:29 EST 2007


Here is a practical example I ran into a few days ago.  With this
expression:

   writeFile path (compute text)

the file at path would be overwritten with an empty file if an error occurs
while evaluating (compute text).  With this one:

  writeFile path $! (compute text)

the file alone when an error occurs.

On Nov 17, 2007 8:04 PM, PR Stanley <prstanley at ntlworld.com> wrote:

> Hi
> okay, so $! is a bit like $ i.e. the equivalent of putting
> parentheses around the righthand expression. I'm still not sure of
> the difference between $ and $!. Maybe it's because I don't
> understand the meaning of "strict application". While we're on the
> subject, what's meant by Haskell being a non-strict language?
> Cheers
> Paul
> At 01:50 15/11/2007, you wrote:
> >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
> >
> >_______________________________________________
> >Haskell-Cafe mailing list
> >Haskell-Cafe at haskell.org
> >http://www.haskell.org/mailman/listinfo/haskell-cafe
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20071209/13c6e7dd/attachment.htm


More information about the Haskell-Cafe mailing list