title: Why can't I get the increased counter value?
body: <p>I am trying to do a global counter using monads in Haskell, I want to get the incremented value every time I use the monad counter, but I am kind of stuck getting the same value each time! 
  The code list is  as follows:</p>
  
  <pre><code>module CounterMonad where
  
  data Counter a = C (Int -&gt; (Int, a))
  
  --reset the counter
  new :: Counter ()
  new = C $ \_ -&gt; (0, ())
  
  -- increment the counter:
  --inc :: Counter Int
  --inc = C $ \n -&gt; (n+1, n)
  inc = get &gt;&gt;= \s -&gt; (put (s+1))
  
  -- returning the current value of the counter
  get :: Counter Int
  get = C $ \n -&gt; (n, n)
  
  --
  put x = C $ \n -&gt; (x, x)
  
  --return is nop, &gt;&gt;= is sequential exectuion
  instance Monad Counter where
      return r = C $ \n -&gt; (n, r)
      (&gt;&gt;=) (C f) g = C $ \n0 -&gt; let (n1, r1) = f n0
                                     C g' = g r1
                                 in g' n1
  
  run :: Counter a -&gt; a
  run (C f) = snd (f 0)
  
  
  tickC  = do
    inc
    c &lt;- get
    return c
  </code></pre>
  
  <p>When I try to execute as <code>run tickC</code>, it always returns 1.
  What I want is everytime I <code>run tickC</code>, it returns the incremented value, like 1, ,2, 3,4 ....
  I know there must be some stupid problem lying there, can you guys point out how?</p>