array package:ghc-internal

Construct an array with the specified bounds and containing values for given indices within these bounds. The array is undefined (i.e. bottom) if any index in the list is out of bounds. The Haskell 2010 Report further specifies that if any two associations in the list have the same index, the value at that index is undefined (i.e. bottom). However in GHC's implementation, the value at such an index is the value part of the last association with that index in the list. Because the indices must be checked for these errors, array is strict in the bounds argument and in the indices of the association list, but non-strict in the values. Thus, recurrences such as the following are possible:
a = array (1,100) ((1,1) : [(i, i * a!(i-1)) | i <- [2..100]])
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. bottom). If, in any dimension, the lower bound is greater than the upper bound, then the array is legal, but empty. Indexing an empty array always gives an array-bounds error, but bounds still yields the bounds with which the array was constructed.
The type of immutable non-strict (boxed) arrays with indices in i and elements in e.
Marshalling support: routines allocating, storing, and retrieving Haskell lists that are represented as arrays in the foreign language
Legacy interface for arrays of arrays. Deprecated, because the Array# type can now store arrays directly. Consider simply using Array# instead of ArrayArray#. Use GHC.Internal.Exts instead of importing this module directly.
Exceptions generated by array operations
Mutable, boxed, non-strict arrays in the ST monad. The type arguments are as follows:
  • s: the state variable argument for the ST type
  • i: the index type of the array (should be an instance of Ix)
  • e: the element type of the array.
The accumArray function deals with repeated indices in the association list using an accumulating function which combines the values of associations with the same index. For example, given a list of values of some index type, hist produces a histogram of the number of occurrences of each index within a specified range:
hist :: (Ix a, Num b) => (a,a) -> [a] -> Array a b
hist bnds is = accumArray (+) 0 bnds [(i, 1) | i<-is, inRange bnds i]
accumArray is strict in each result of applying the accumulating function, although it is lazy in the initial value. Thus, unlike arrays built with array, accumulated arrays should not in general be recursive.
Construct an array from a pair of bounds and a list of values in index order.