[Haskell-cafe] Tackling IO (the correct way)
dukedave at gmail.com
Thu Aug 23 01:04:54 EDT 2007
Hi again all, I could do with some design pointers for a project I'm
working on combining Haskell with a robot.
My situation is:
I read sensor data from the robot lazily a line at a time, as soon as
a line is read in my code sends out a response down a pipe.
Implemented in this fashion:
> mapM_ (updateFunction myIORef) fromRobot ::IO ()
> fromRobot :: String
> updateFunction :: IORef -> String -> IO ()
Now I wish to update a HOpenGL window synchronously with this.
To establish this I make a new HOpenGL window & return an IORef (IO
()) which holds the actions to draw my graphics. In this fashion:
> myIORef <- makeWindow
--- Above code ---
This can be passed to updateFunction as shown above so every time it
processes a new line from the robot is can update the graphics via the
Because neither 'mapM_ (updateFunction myIORef) fromRobot' nor
'mainLoop' terminate I've been using 'forkIO' to split one off. This
way the lazy evaluation keeps running and then window keeps updating
This works, sort of.
I have problems because the my HOpenGL code also has magic to allow
you to change the point of view using the keyboard. But when I do I
get this after a while:
Can anyone suggest how to resolve this "two functions which never
terminate but both share IORefs" problem?
More information about the Haskell-Cafe