[Haskell-cafe] More STUArray questions
mpercossi at martinpercossi.com
Sun Mar 12 14:20:48 EST 2006
On Sun, Mar 12, 2006 at 09:15:57PM +0200, Einar Karttunen wrote:
> On 12.03 18:44, Martin Percossi wrote:
> > However, just out of curiosity, I'm still curious at how I could do the
> > runSTMatrix, which would really be the icing on the cake in terms of client
> > usability.
> You might want to look at the definition of Data.Array.ST
> (at http://darcs.haskell.org/packages/base/Data/Array/ST.hs)
> runSTUArray is defined as follows:
> runSTUArray :: (Ix i)
> => (forall s . ST s (STUArray s i e))
> -> UArray i e
> runSTUArray st = runST (st >>= unsafeFreezeSTUArray)
> A similar way should work for matrixes.
Tried the following:
unsafeFreezeMatrix :: MMatrix s -> ST s Matrix
unsafeFreezeMatrix (MMatrix x1 x2 marray) = do block <- unsafeFreeze marray
return $ Matrix x1 x2 block
runSTMatrix :: (forall s . ST s (MMatrix s)) -> Matrix
runSTMatrix st = runST (st >>= unsafeFreezeMatrix)
but I get the error:
Couldn't match `MMatrix s' against `ST s1 (MMatrix s1)'
Expected type: ST s1 (MMatrix s1) -> . (forall s1) b
Inferred type: MMatrix s -> ST s Matrix
In the second argument of `(>>=)', namely `unsafeFreezeMatrix'
In the first argument of `runST', namely `(st >>= unsafeFreezeMatrix)'
More information about the Haskell-Cafe