[Haskell-cafe] How to variables

yin yin at atom.sk
Mon Jul 18 17:25:28 EDT 2005

robert dockins wrote:

>>>> I'm doing a 3D simulation. Now I need something like variables in
>>>> imperative languages. My mainLoop check for new events and renders
>>>> scene.
>>> Then you want IORef.
>>> http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data.IORef.html
>> I saw it. The problem is, I need an amount of 100*X of mutable variables
>> to implement the system (camera position, rotation, aceleration, ...,
>> position and deformetion infomations for every object, ..., renderer
>> situations [like temprary fading and other efects], ... and more)
> Then you probably want a big labeled record, 

Uhm... and what if I write some runtines in plain C, then bind them to
Haskell and and use then as in OOP:

  struct camera {
    GLfloat x, y, z;
  struct camera getCameraPos() {... /* returns camera position */}
  void setCameraPos(struct camera c) {... /* sets position of camera */}
  -- just define bindings


  mainLoop = do
  -- read events
  -- on KeyDown (SDLK_Keft) -> do
  --    (x, y, z) <- getCameraPos
  --    setCameraPos (x + 1, y, z)
  -- ...
  -- drawGLScreen

  drawGLScreen = do
  --   glTranslate to getCameraPos...

Is this apoarch safe enougth, what do you think?

Matej 'Yin' Gagyi

More information about the Haskell-Cafe mailing list