
jules:
Achim Schneider wrote:
things like
data State = State { winSize :: IORef Size , t :: IORef Int , fps :: IORef Float , showFPS :: IORef Bool , showHelp :: IORef Bool , grabMouse :: IORef Bool , mousePos :: IORef (Maybe Position) , mouseDelta :: IORef Position , viewRot :: IORef Vec3 , angle' :: IORef GLfloat , ballPos :: IORef Vec2 , ballVel :: IORef Vec2 }
Yuck!
I'm not sure whether this is a real example or not, but if it's real, get rid of all those IORefs. Make State a simple type, and use (IORef State) as needed for callbacks, and hide that fact in other code.
I agree, this is very-unHaskelly :) The State type should be a simple purely functional structured, threaded through your code via a StateT or some such. Not a bunch of pointers in IO. See xmonad for examples of this in highly effectful programs, http://code.haskell.org/xmonad/XMonad/Core.hs newtype X a = X (ReaderT XConf (StateT XState IO) a) (Carries read-only and updatable state components) -- Don