[Haskell-cafe] Storing functional values

Tomasz Zielonka t.zielonka at students.mimuw.edu.pl
Fri Jan 30 17:45:10 EST 2004

On Fri, Jan 30, 2004 at 09:21:58AM -0700, nickgrey at softhome.net wrote:
> Hi, 
> I'm writing a game in Haskell.  The game state includes a lot of closures.  
> For example, if a game object wants to trigger an event at a particular 
> time, it adds a function (WorldState -> WorldState) to a queue.  Similarly 
> there are queues which contain lists of functions which respond to events.  
> (CreatureAttackEvent -> WorldState -> WorldState) 
> I'd like to be able to save the game state to disk so that it can be 
> reloaded.  Obviously, these closures are now a problem, as they can't be 
> stored. 
> I could obviously, replace all the functional values with non-functional 
> ones, and have a big case statement specifying the behaviour associated 
> with each constant.  However, I don't really like this solution.

Just a vague idea: I think it would be possible to apply some kind of
automatic whole-program transformation that would do most (if not all)
the work for you. The relevant keywords may be "defunctionalisation",
"closure conversion".

Do you want to be able to save game in one version of the program and
restore it in a newer version? This can be difficult.

Best regards,

.signature: Too many levels of symbolic links

More information about the Haskell-Cafe mailing list