Considering the Haskell code:
do -- it's IO !!!
...
!x <- someFunction
... usage of x
how useful is !
here? It’s a result of monadic (it’s IO
!) evaluation, so my questions are:
-
if
x
is a primitive type likeUTCTime
(getCurrentTime
for example),Int
,Bool
– does!
make sense? -
if
x
has “head” likeString
,Map k v
, some record maybe? Thenx
can be lazy? How lazy? Does it mean that when I will usex
later then realIO
happens? -
Does
IO
monad have some more specific behavior in this context? Like little bit more strict than other (more “pure”) monads?
By default I/O is lazy, then how does Haskell know when to call it immediately (passing through this expression) or when to substitute it with a thunk? By type of x
? Something like: GHC has a list of primitive types and everything outside the list is substituted?
Any explanations are appreciated.