[Haskell-cafe] Doing without IORef

Claude Heiland-Allen claudiusmaximus at goto10.org
Thu Apr 3 06:41:50 EDT 2008

Jinwoo Lee wrote:
> Hi,
> Recently I wrote a code that uses readline library 
> (System.Console.Readline).
> I had to maintain a state (file path) and do IO throughout the code, so 
> I decided to use StateT monad.
> The problem was that in order to retrieve the current state (file path) 
> inside the handler that had been registered by using bindKey function of 
> readline, I had to resort back to using IORef rather than using the 
> state stored in the StateT monad. It's because the handler for bindKey 
> should have the type of Int -> Char -> IO Int.


> Is there any way in which I can do without IORef in tabHandler and 
> commandLoop (written in red and bold, if you can see)?

Probably not, but this is worth a read if you want to hide the plumbing 
behind the scenes a bit:

"Monadic tunnelling: the art of threading one monad through another"


More information about the Haskell-Cafe mailing list