
I agree with you. My work-around is then to define foo and bar locally to testfunc, in the scope of r:
testfunc = do r <- newSTRef ('x',0) let foo = do (c,n) <- readSTRef r writeSTRef r ('a', n+1) bar = do (c,n) <- readSTRef r writeSTRef r (c,n+2) foo bar (c,n) <- readSTRef r return n
Thought about that to... but it looks kind of... terribly ugly (sorry :)
But if this looks like unsatisfactory (it does to me, too), perhaps you have to go back to DIY monads. DIY? what does that means?
DIY monads are good when: you fix the state variables, you don't want to mention them in subprogram parameters. Yeap!
The ST monad is good when: you create more state variables on the fly, you use mutable arrays, you don't want to write your own monad and put/get commands.
What if you want both and keep nice clean(*) programming style... :-) J.A. (*) Clean as in "not dirty", not Clean the FL.