
m would have to be IO, c would be a bit pointless - so IO () is a better return type. It doesn't have to be IO. It can also be implemented using liftIO . modify .. Then you can use htis modify function from any monad beeing an instance of IOMonad..
You can then Hoogle for it: IORef a -> (a -> a) -> IO ()
http://haskell.org/hoogle/?q=IORef%20a%20-%3E%20(a%20-%3E%20a)%20-%3E%20IO%2...)
... = do (New count) <- modify ioCounterRef (+1)
= do newcount <- modifyIORef ioCounterRef (+1)
It already exists :) Hi Neil. Thanks for your hint. This time I already have found modifyIORef ;) But as hoogle states:
Searched for modifyIORef Results 1 - 2 of 2 Data.IORef. modifyIORef :: IORef a -> (a -> a) -> IO () Data.IORef. atomicModifyIORef :: IORef a -> (a -> (a, b)) -> IO b the return type of modifyIORef is IO (), not IO <new value> So only using this function wouldn't solve the problem, right? Marc