H98: Ix class

Marcin 'Qrczak' Kowalczyk qrczak@knm.org.pl
11 Sep 2001 16:02:06 GMT

Tue, 11 Sep 2001 09:16:11 -0400, Jan-Willem Maessen <jmaessen@alum.mit.edu> pisze:

> Just to clarify, do we still require identities (1) and (3) below
> (pasted from the Library report and numbered)?  That is, is range
> obliged to yield its results in strict index order?  [This rules out
> Ix instances that do, e.g., blocked iteration unless the array itself
> is also re-blocked.  Reblocking the array itself is arguably a good
> idea, but may not be what we expect...]
> 1)   range (l,u) !! index (l,u) i == i   -- when i is in range
> 2)   inRange (l,u) i == i `elem` range (l,u)
> 3)   map index (range (l,u))      == [0..rangeSize (l,u)]

The current implementation of Array in ghc iterates relies on them.
It iterates either over array elements in the stored order or over
range, whichever is more convenient for efficient implementation of
the particular operation.

For example elems is described in Haskell 98 as [a!i | i <- indices a],
but ghc just picks elements in the stored order without computing index
values or bounds checking.

 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
  ^^                      SYGNATURA ZASTĘPCZA