[Haskell-cafe] What is the role of $!?
Dean Herington
heringtonlacey at mindspring.com
Mon Dec 10 21:43:10 EST 2007
Thanks, Tom, for a nice description of lazy evaluation.
Besides the minor things Derek pointed out, there's one more subtle
but important thing to correct:
At 7:29 AM +0000 11/29/07, Thomas Davie wrote:
>
>$! is the special case, which means strictly apply. It evaluates
>its argument first, *then* does the application. This may or may
>not be faster (and usually isn't, due to evaluating more of the
>argument):
>
>f ($!) x = seq x (f x)
>
>seq is a special function that says "first fully evaluate my first
>argument, then return my second argument", it breaks non-strict
>semantics.
seq doesn't fully evaluate its first argument, rather only to what's
called "weak head normal form". Roughly, that means only enough to
establish the top-level constructor (e.g., to distinguish [] from
(_:_)).
Dean
More information about the Haskell-Cafe
mailing list