45 points · by mzehrer · 13y ago · 11 comments
startDownload = do
file <- atomically $ do
f <- getQueuedFile
push f currentDownLoads
return f
startDownloadThread file
How can that push be non-side-effecting and still do something sensible? If the snippet is replayed, won't multiple pushes happen? This may be a question only joeyh can answer, if this is something specific to his code base...Naively, I would write something like (again, my Haskell not so good):
startDownload = do
file <- atomically $ getQueuedFile
push f currentDownLoads
startDownloadThread fileAnd in the first snippet it is in STM monad, and you can do, for example
modifyTVar :: TVar a -> (a -> a) -> STM ()
You should understand monads more to grok it, it's quite beautiful.