Hello Grzegorz,
Wednesday, September 23, 2009, 7:19:59 PM, you wrote:
> This seems like a bug in the implementation of writeArray: when passed
> let (l,u) = ((0,10),(20,20))
writeArray computes raw index (from 0 to total number of array
elements) and check that this index is correct. with multi-dimensional
arrays this approach may lead to wrong results, as you mentioned. it's
known problem that isn't fixed for a long time probably due to
efficiency cautions. the error is here:
data Ix i => Array i e
= Array !i -- the lower bound, l
!i -- the upper bound, u
!Int -- a cache of (rangeSize (l,u))
-- used to make sure an index is
-- really in range
(Array# e) -- The actual elements
(!) :: Ix i => Array i e -> i -> e
arr@(Array l u n _) ! i = unsafeAt arr $ safeIndex (l,u) n i
safeIndex :: Ix i => (i, i) -> Int -> i -> Int
safeIndex (l,u) n i = let i' = unsafeIndex (l,u) i
in if (0 <= i') && (i' < n)
then i'
else error "Error in array index"
obviously, safeIndex should use inRange call instead
--
Best regards,
Bulat mailto:[email protected]
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe