unsafePerformIO and IORefs

Ashley Yakeley ashley@semantic.org
Mon, 18 Nov 2002 14:32:45 -0800


At 2002-11-18 11:05, Sven Panne wrote:

>global :: a -> IORef a
>global a = unsafePerformIO (newIORef a)

This is useful, you can do this with it:

  ref = global Nothing

  convert :: a -> IO b
  convert a = do
    writeIORef ref (Just a)
    Just b <- readIORef ref
    return b


-- 
Ashley Yakeley, Seattle WA