[Haskell-cafe] Doing without IORef
Brandon S. Allbery KF8NH
allbery at ece.cmu.edu
Thu Apr 3 11:58:13 EDT 2008
On Apr 3, 2008, at 6:03 , Jinwoo Lee wrote:
> Recently I wrote a code that uses readline library
> 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.
You can hide the IORef inside the StateT... but this is one of
several cases where I *really* wish the callbacks were MonadIO a
=> ... -> a t.
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university KF8NH
More information about the Haskell-Cafe