
30 Jun
2011
30 Jun
'11
1:28 a.m.
On Thu, Jun 30, 2011 at 8:21 AM, Ertugrul Soeylemez
Christopher Done
wrote: I tend to use Control.Monad.Reader for stateful stuff like this. It is found in the mtl package http://hackage.haskell.org/package/mtl-2.0.1.0
How would you use reader for a counter?
Reader is a good choice for an interthread counter:
MonadIO m => ReaderT (TVar Int) m
I think, then people are talking about global variables in Haskell, what they really want is such a thing.
Greets, Ertugrul
Though in this case, you can go with the cheaper IORef, since (presumably) the only operation is going to be incrementing the counter. Just be sure to use atomicModifyIORef[1]. Michael [1] http://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/Data-IORef...