File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -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)
You can’t perform that action at this time.
0 commit comments