[Haskell] threading mutable state through callbacks

Sven Panne Sven.Panne at aedion.de
Fri Oct 8 14:17:57 EDT 2004

Jules Bean wrote:
> [...] Unfortunately, it's not going to work. It's not going to work because 
> some of the procedures take callbacks, and the callbacks are values of 
> type IO (). I can see two solutions to this:
> a) revert to using an IORef [...]
> b) write the callbacks as values of type StateT Env IO () [...]


c) Give up any hope of clean semantics and simply use a common hack like:

       {-# NOINLINE myGlobalVar #-}
       myGlobalVar :: IORef Int
       myGlobalVar = unsafePerformIO (newIORef 0)

    My GLUT binding does it happily, as does GHC itself, just look for NOINLINE
    pragmas in the following files:     :-]



More information about the Haskell mailing list