[Haskell-cafe] How to implement nested loops with tail recursion?

Johan Tibell johan.tibell at gmail.com
Wed Sep 19 20:35:37 CEST 2012

On Wed, Sep 19, 2012 at 8:00 PM,  <sdiyazg at sjtu.edu.cn> wrote:
> So how do I force IO actions whose results are discarded (including IO ()) to be strict?

In your particular case it looks like you want
Data.IORef.modifyIORef'. If your version of GHC doesn't include it you
can write it like so:

-- |Strict version of 'modifyIORef'
modifyIORef' :: IORef a -> (a -> a) -> IO ()
modifyIORef' ref f = do
    x <- readIORef ref
    let x' = f x
    x' `seq` writeIORef ref x'

-- Johan

More information about the Haskell-Cafe mailing list