Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does $! mean / do in Haskell? [duplicate]

Tags:

syntax

haskell

Context:

do state1 <- act state
   dispatch $! state1

What $! does ?

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

like image 616
cnd Avatar asked Dec 26 '22 04:12

cnd


1 Answers

$! 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.

like image 152
Ørjan Johansen Avatar answered Jan 06 '23 03:01

Ørjan Johansen