[Haskell-cafe] Getting my mind around UArray -> STUArray conversion

Scott Michel scooter.phd at gmail.com
Fri Jun 19 21:43:29 EDT 2009


I'm trying to get my mind around how to thaw and then freeze a UArray.
Theoretically, what I've written below should be a no-op, but I keep
getting typing errors that I can't figure out. GHCI 6.10.3 says:

Couldn't match expected type `UArray ix a'
           against inferred type `ST s (STUArray s ix1 e)'
    In the first argument of `(>>=)', namely
        `(unsafeThaw mem :: ST s (STUArray s ix e))'
    In the expression:
          (unsafeThaw mem :: ST s (STUArray s ix e))
        >>=
          (\ mmem -> unsafeFreeze mmem)
    In the definition of `wombat':
        wombat val idx mem
                    = (unsafeThaw mem :: ST s (STUArray s ix e))
                    >>=
                      (\ mmem -> unsafeFreeze mmem)

I'm figuring that usafeThaw with the type annotation should have given
GHIC enough clue.

Any suggestions?


-scooter
 (WOMBAT = Waste Of Money Brains And Time)

import Control.Monad;
import Control.Monad.ST;
import Data.Array.ST;
import Data.Array.Unboxed;
import Data.Array.MArray;
import Data.Word;

wombat :: (IArray UArray e, Ix ix, MArray (STUArray s) e (ST s)) => e
-> ix -> UArray ix e -> UArray ix e
wombat val idx mem = (unsafeThaw mem :: ST s (STUArray s ix e)) >>=
(\mmem -> unsafeFreeze mmem)


More information about the Haskell-Cafe mailing list