4

Context:

do state1 <- act state
   dispatch $! state1

What $! does ?

E.g. why it's not just dispatch state1 here?

cnd
  • 32,616
  • 62
  • 183
  • 313
  • 10
    Hello neighbor, have you heard the good word about our lord and savior [Hoogle](http://www.haskell.org/hoogle/?hoogle=%24%21)? – Chris Martin Sep 23 '14 at 05:57

1 Answers1

12

$! is strict application, the difference from dispatch state1 is that state1 is guaranteed to be evaluated and not just kept as a lazy thunk. It's defined as

f $! x  = x `seq` f x

Forcing evaluation in this way can be important for efficiency issues, such as preventing memory leaks.

Ørjan Johansen
  • 18,119
  • 3
  • 43
  • 53