[Haskell-cafe] How to use STArray?

Remi Turk rturk at science.uva.nl
Sat Aug 27 11:31:36 EDT 2005

On Fri, Aug 26, 2005 at 08:27:43PM -0400, ChrisK wrote:
> to figure out since there was no Data.Array.ST.Lazy.  Does anyone know
> why it was left out?  I'll put a note on the HaskellTwo page about that...

Some time ago when I wanted a lazy hashtable I came up with this,
which, after minimal testing, seemed to work:
(Lazy STRef's are implemented in exactly the same way, btw)


{-# OPTIONS -fglasgow-exts #-}
module MArrayLazyST (
    module Data.Array.MArray
) where

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

instance MArray (STArray s) e (ST s) where
    newArray range e = strictToLazyST (newArray range e)
    newArray_ range = strictToLazyST (newArray_ range)
    unsafeRead arr i = strictToLazyST (unsafeRead arr i)
    unsafeWrite arr i e = strictToLazyST (unsafeWrite arr i e)



Nobody can be exactly like me. Even I have trouble doing it.

More information about the Haskell-Cafe mailing list