

STM in Haskell - mzehrer
http://joeyh.name/blog/entry/the_newinwheezy_game:_STM/

======
jonke
I do think this example
[http://computationalthoughts.blogspot.se/2008/03/some-
exampl...](http://computationalthoughts.blogspot.se/2008/03/some-examples-of-
software-transactional.html) is a lot better than the one in the article.

------
krig
As a complete Haskell noob, I'm wondering about the push in this snippet:

    
    
      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 file

~~~
svedin
push doesn't have to be non-side-effecting. You are allowed to modify shared
state, as long as it is a TVar (shared memory that supports transactions).

~~~
krig
Right, of course. Thank you. :)

