Commit 36b66438 authored by simonmar's avatar simonmar
Browse files

[project @ 2001-08-29 09:35:32 by simonmar]

Update this test for the changes to the Ix class.  In particular, we
can no longer depend on Eq being a superclass of Ix, so when comparing
indices we have to use Ix.index and comapre the Int results.
parent ac43c831
......@@ -155,7 +155,7 @@ array :: (Ix a) => (a,a) -> [(a,b)] -> Array a b
array b ivs =
if and [inRange b i | (i,_) <- ivs]
then MkArray b
(\j -> case [v | (i,v) <- ivs, i == j] of
(\j -> case [v | (i,v) <- ivs, index b i == index b j] of
[v] -> v
[] -> error "Array.!: \
\undefined array element"
......@@ -183,8 +183,11 @@ assocs a = [(i, a!i) | i <- indices a]
(//) :: (Ix a) => Array a b -> [(a,b)] -> Array a b
a // us = array (bounds a)
([(i,a!i) | i <- indices a \\ [i | (i,_) <- us]]
([(i,a!i) | i <- indices a,
index b i `notElem` new_indices]
++ us)
where b = bounds a
new_indices = map (index b . fst) us
accum :: (Ix a) => (b -> c -> b) -> Array a b -> [(a,c)]
-> Array a b
......@@ -201,10 +204,10 @@ ixmap b f a = array b [(i, a ! f i) | i <- range b]
instance (Ix a) => Functor (Array a) where
fmap fn (MkArray b f) = MkArray b (fn . f)
instance (Ix a, Eq b) => Eq (Array a b) where
instance (Ix a, Eq a, Eq b) => Eq (Array a b) where
a == a' = assocs a == assocs a'
instance (Ix a, Ord b) => Ord (Array a b) where
instance (Ix a, Ord a, Ord b) => Ord (Array a b) where
a <= a' = assocs a <= assocs a'
instance (Ix a, Show a, Show b) => Show (Array a b) where
......@@ -213,7 +216,7 @@ instance (Ix a, Show a, Show b) => Show (Array a b) where
shows (bounds a) . showChar ' ' .
shows (assocs a) )
instance (Ix a, Read a, Read b) => Read (Array a b) where
instance (Eq a, Ix a, Read a, Read b) => Read (Array a b) where
readsPrec p = readParen (p > 9)
(\r -> [(array b as, u) | ("array",s) <- lex r,
(b,t) <- reads s,
......@@ -506,4 +509,4 @@ instance Observable StdGen where { observer = observeBase }
instance Observable a => Observable (Gen a) where
observer (Gen a) = send "Gen" (return (Gen) << a)
-}
\ No newline at end of file
-}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment