You can think about your second version as without side-effects too. It's just in IO monad. Actually, all IO is kinda pure, just (IO smth) values fly behind the scenes. All dirty unpure things happen in runtime.
And 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.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).
Right, of course. Thank you. :)
Haskell isn't non-side-effecting. It's just a bit more sane and structured about when and how.
Nobody said that anyway. I doubt there's such a thing as non-side-effecting languages :)
Sure there are, they just are interpreted in side-effecting interpreters. Lambda calculus comes to mind.
Anything that happens in the STM monad can be undone if something is wrong. If you for example write to a TVal but another thread was doing it at the same time, one of the threads won't have its changes go through until the transaction is retried. Of course this is all invisible to the person using STM.
Who said it was non-side-effecting?
Naively, I would write something like (again, my Haskell not so good):