On 12/13/05, Sebastian Sylvan <[EMAIL PROTECTED]> wrote: > There is no plan to provide an implementation of this (the > Array-of-TVar approach) in the libs? With an MArray instance? > It would be nice if you could just plug i into existing functions > operating on MArray...
I hacked this up, see if it works: {-# OPTIONS -fglasgow-exts #-} module Control.Concurrent.STM.TMArray ( TArray ) where import Control.Monad (replicateM) import Data.Array (Array) import Data.Array.Base (listArray, arrEleBottom, unsafeAt, MArray(..), HasBounds(..)) import Data.Ix (rangeSize) import Control.Concurrent.STM (STM, TVar, newTVar, readTVar, writeTVar) newtype TArray i e = TArray (Array i (TVar e)) instance MArray TArray e STM where newArray b e = do a <- replicateM (rangeSize b) (newTVar e) return $ TArray (listArray b a) newArray_ b = do a <- replicateM (rangeSize b) (newTVar arrEleBottom) return $ TArray (listArray b a) unsafeRead (TArray a) i = readTVar $ unsafeAt a i unsafeWrite (TArray a) i e = writeTVar (unsafeAt a i) e instance HasBounds TArray where bounds (TArray a) = bounds a -- Taral <[EMAIL PROTECTED]> "Computer science is no more about computers than astronomy is about telescopes." -- Edsger Dijkstra _______________________________________________ Haskell mailing list Haskell@haskell.org http://www.haskell.org/mailman/listinfo/haskell