I'm learning a bit of functional programming in Gambit-C Scheme by restricting myself to not using set!. I thought it might be fun to write a little OpenGL game using this environment, which seems to lend itself well to game development.
However, it seems to be difficult to stick to a functional style and avoid global state when using OpenGL and GLUT. I don't think this is a fundamental limitation of game programming, per se, but a callback-based API such as GLUT does not seem to work well with functional programming.
For example, I'm trying to think of the world as a stream of mutating state vectors which is a function of an interleaved list of timestep and user input events. This idea seems to be okay, but it doesn't seem to go easily with asynchronous programming. For instance, I have to register a callback for GLUT's display function, which should somehow be able to access the "current" item in this stream. Meanwhile, there's nothing to drive the stream forward by taking from it.
Ideally, I'd need something that is sort of "outside" GLUT, a main function which somehow depends (perhaps monadically) on the various GLUT functions having been executed at some point. How could such a style of game engine be developed around GLUT, or another way to ask is how could I most successfully isolate GLUT from my engine? Is it possible to have GLUT generate such an interleaved list of events to an outside procedure? How does Haskell handle this, for instance?