[Haskell-cafe] Current situation regarding global IORefs
Brian Hulley
brianh at metamilk.com
Fri Apr 21 09:56:02 EDT 2006
Hi -
I've run into the global mutable state problem described in
http://www.haskell.org/hawiki/GlobalMutableState
Since the page was last edited in March last year, I'm wondering if there
have been any developments or further thoughts on how to safely create top
level IORefs since they are absolutely essential for the library I'm
writing.
For my library, which implements a GUI, I have a Manager module which keeps
track of which control currently has the keyboard focus etc, and I don't
want to have to pass round the state of the manager to every control since
this would be monstrously inconvenient and a total waste of space/time, so
at the moment I'm reduced to:
module Manager where
keyboard :: IORef (Maybe Control)
{-# NOINLINE keyboard #-}
keyboard = unsafePerformIO $ newIORef Nothing
The problem is that I don't know if this is guaranteed to be completely safe
for all Haskell compilers or even for all future versions of ghc (?)
Thanks, Brian.
More information about the Haskell-Cafe
mailing list