Mon Apr 16 08:19:57 EDT 2012
Just update state.
What's the simplest way to have a collection of mutable variables?
I'm writing an animation state update routine and the number of
parameters is getting quite large, so it becomes hard to do something
update (Params a b c ...) = Params a' b' c' where
a' = ...
b' = ...
c' = ...
also because not all parameters are updated at each step.
Maybe this is a symptom of bad factoring, but frankly I don't have the
time right now to look into it too deeply, so I wonder how to do just
have "no fuss mutable state".
From memory this seems to be the ST monad and STRef, which is like IO
and IOref, except that it can be executed like this:
1. create a bunch of STRef from immutable data (= thaw)
2. perform mutable computations on STRef
3. copy contents of STRefs to immutable data (= freeze)