Where prelude alternatives/ classes and types to get values?
marco-oweber at gmx.de
Sat Feb 17 13:13:08 EST 2007
> 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 ()
> ... = do (New count) <- modify ioCounterRef (+1)
> = do newcount <- modifyIORef ioCounterRef (+1)
> It already exists :)
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?
More information about the Libraries