Mon Dec 5 19:03:52 EST 2011


So... How to make Value work with STUArray / ST[2].  I think it's best
to make the interface a bit more general though, and start with

import Control.Monad.ST
import Data.Array.ST
import Data.Array.MArray
import Data.Array.Base

This seems to be it:

instance (Monad m, MArray a t m) => Array m Value (a Int) t where
  _get (Value a) (Value i) =           liftM Value $ readArray a i
  _set (Value a) (Value i) (Value e) = liftM Value $ writeArray a i e

Now, how to use it?  To test it, let's try to write a "sum" program.
This involves the whole bazar: computations, conditionals, loops and

[1] http://www.haskell.org/ghc/docs/latest/html/libraries/array/Data-Array-MArray.html
[2] http://www.haskell.org/ghc/docs/6.10.4/html/libraries/base/Control-Monad-ST.html#t%3AST
[3] http://www.haskell.org/haskellwiki/Arrays#Mutable_arrays_in_ST_monad_.28module_Data.Array.ST.29