Standard Array library question

Jeff Newbern jnewbern@nomaware.com
08 May 2003 18:35:25 +0100


Hello,

I have a question regarding the standard Array library.  In the
Haskell98 report, section 16.1 it says:

  Not every index within the bounds of the array need appear in the
  association list, but the values associated with indices that do not
  appear will be undefined (i.e. _|_).

However, this feature seems to be of diminished value because of the way
the Array.indices function is defined in section 16.4:

  indices :: (Ix a) => Array a b -> [a]
  indices = range . bounds

Since this returns all of the indices within the array bounds, even the
ones that are undefined, it causes other functions in the
Array module that use indices to build lists with undefined elements.
These are fine due to lazy evaluation, but it means that such arrays
cannot be shown or used in a strict manner.

If I do "indices (array (1,3) [(1,1),(3,9)])", I would like to get [1,3]
not [1,2,3].  Then for "elems ..." I would get [1,9] not [1,_|_,9].

So first: Is there a good reason for the current definition?

And second: Is there any way to get the behavior I want within the
existing set of libraries.  For instance, an isDefined predicate could
help.

Thanks,
Jeff Newbern