Large recursive data in Haskell
Posted: Fri Aug 28, 2009 5:48 pm
I'm attempting to use Haskell to build a game as a learning experience. I'm trying to do this a purely functional as possible (with some exceptions such as OpenGL being state based). The thing is, games are nothing but state, so in order to store the state I'll have to pass it back recursively, for example:
However, will not all this copying of state around have a severe performance penalty?
It might be okay for a simple Space Invaders game, but the game I'm trying to do has close to 1,000,000 nodes in the terrain plus possibly hundreds of values to pass around. The thought of storing that in a single list that gets copied multiple times per frame makes me shudder.
I could use a difference list, but that could still create somewhat of an unnecessary overhead? And by structuring the list as smaller sublists, it would only have to do a copy of the top level, and not each lower level? For example:
And lastly, if something like "All Objects" was a list with 10,000 entries in there, if I reference by ID/index, it will iterate through each node from the start because because Haskell lists are linked lists? The alternative is I use an IO Array, but that would force most of my functions to be monadic, in which case I might as well be using C++.
Thanks.
Code: Select all
playFrame state = do
state $= doLogicFrame state
state $= doRenderFrame state -}
playFrame state
It might be okay for a simple Space Invaders game, but the game I'm trying to do has close to 1,000,000 nodes in the terrain plus possibly hundreds of values to pass around. The thought of storing that in a single list that gets copied multiple times per frame makes me shudder.
I could use a difference list, but that could still create somewhat of an unnecessary overhead? And by structuring the list as smaller sublists, it would only have to do a copy of the top level, and not each lower level? For example:
Code: Select all
[Game State,
[] Updatable Objects,
[] All Objects
Root Terrain Node,
Root Collision Quadtree Node,
Root Rendering Node]
Thanks.