Standard Array library question

Iavor Diatchki diatchki@cse.ogi.edu
Thu, 08 May 2003 10:46:16 -0700


hello,

if you want an array in which you do not want to specify all elements, 
and later
only get the ones that are "defined", you should use an array of  
"Maybe" type.

you can set elements that are "undefined" to "Nothing", and the rest to 
"Just something".
then you can define:
myindeces = catMaybes  . indices

bye iavor


Jeff Newbern wrote:

>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
>
>
>_______________________________________________
>Haskell mailing list
>Haskell@haskell.org
>http://www.haskell.org/mailman/listinfo/haskell
>
>  
>