@@ -25,7 +25,7 @@ module Control.Concurrent.STM.TArray (
25
25
import Data.Array (Array , bounds )
26
26
import Data.Array.Base (listArray , arrEleBottom , unsafeAt , MArray (.. ),
27
27
IArray (numElements ))
28
- import Data.Ix (rangeSize )
28
+ import Data.Ix (Ix ( rangeSize ) )
29
29
import Data.Typeable (Typeable )
30
30
import Control.Concurrent.STM.TVar (TVar , newTVar , readTVar , writeTVar )
31
31
#ifdef __GLASGOW_HASKELL__
@@ -41,7 +41,18 @@ import Control.Sequential.STM (STM)
41
41
-- but it may be replaced by a more efficient implementation in the future
42
42
-- (the interface will remain the same, however).
43
43
--
44
- newtype TArray i e = TArray (Array i (TVar e )) deriving (Eq , Typeable )
44
+ newtype TArray i e = TArray (Array i (TVar e )) deriving (Typeable )
45
+
46
+ -- There are no provisions for moving/copying TVars between TArrays.
47
+ -- Therefore, two TArrays are equal if and only if they are both empty or are
48
+ -- actually the same array in memory. We have no safe operations for checking
49
+ -- that directly (though in practice we could use `unsafeCoerce#` with
50
+ -- `sameMutableArray#`). So instead we take a quick look at the array sizes and
51
+ -- then decide based on the first TVar of each.
52
+ instance Ix i => Eq (TArray i e ) where
53
+ TArray t1 == TArray t2
54
+ = numElements t1 == numElements t2
55
+ && (numElements t1 == 0 || unsafeAt t1 0 == unsafeAt t2 0 )
45
56
46
57
instance MArray TArray e STM where
47
58
getBounds (TArray a) = return (bounds a)
0 commit comments