[Haskell-cafe] Questions about concurrency and laziness
argantonio at gmail.com
Thu Jun 11 11:35:38 UTC 2015
First of all, apologies if this is not the right place to ask this question.
I'm reading the book "Parallel and concurrent programming in Haskell" and
I'm having some issues reasoning about the impact of laziness.
Looking at the first example in chapter 8 
main = do
m1 <- newEmptyMVar
m2 <- newEmptyMVar
forkIO $ do
r <- getURL "http://www.wikipedia.org/wiki/Shovel"
putMVar m1 r
forkIO $ do
r <- getURL "http://www.wikipedia.org/wiki/Spade"
putMVar m2 r
r1 <- takeMVar m1
r2 <- takeMVar m2
print (B.length r1, B.length r2)
I don't understand why this function is not just putting an unevaluated
thunk in the MVar. Well, I assume that getURL is an eager function, but
looking at its code  or at the documentation of Network.Browser  I
don't see why...
Am I looking at this wrong? Is there any rule of thumb to be used in these
cases? I have the impression that it's really easy to end up creating
thunks in parallel threads and evaluating them in the main one...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe