Module Data.Array

Implementation of Arrays with Braun Trees. Conceptually, Braun trees are always infinite. Consequently, there is no test on emptiness.

Summary of exported operations:

emptyErrorArray :: Array a   
Creates an empty array which generates errors for non-initialized indexes.
emptyDefaultArray :: (Int -> a) -> Array a   
Creates an empty array, call given function for non-initialized indexes.
(//) :: Array a -> [(Int,a)] -> Array a   
Inserts a list of entries into an array.
update :: Array a -> Int -> a -> Array a   
Inserts a new entry into an array.
applyAt :: Array a -> Int -> (a -> a) -> Array a   
Applies a function to an element.
(!) :: Array a -> Int -> a   
Yields the value at a given position.
listToDefaultArray :: (Int -> a) -> [a] -> Array a   
Creates a default array from a list of entries.
listToErrorArray :: [a] -> Array a   
Creates an error array from a list of entries.
combine :: (a -> b -> c) -> Array a -> Array b -> Array c   
combine two arbitrary arrays
combineSimilar :: (a -> a -> a) -> Array a -> Array a -> Array a   
the combination of two arrays with identical default function and a combinator which is neutral in the default can be implemented much more efficient

Exported datatypes:


Array

Constructors:


Exported operations:

emptyErrorArray :: Array a   

Creates an empty array which generates errors for non-initialized indexes.

emptyDefaultArray :: (Int -> a) -> Array a   

Creates an empty array, call given function for non-initialized indexes.

Example call:
(emptyDefaultArray default)
Parameters:
  • default : function to call for each non-initialized index
Further infos:
  • solution complete, i.e., able to compute all solutions

(//) :: Array a -> [(Int,a)] -> Array a   

Inserts a list of entries into an array.

Example call:
(array // modifications)
Parameters:
  • array : array to modify
  • modifications : list of new (indexes,entries) If an index in the list was already initialized, the old value will be overwritten. Likewise the last entry with a given index will be contained in the result array.
Further infos:
  • defined as left-associative infix operator with precedence 9

update :: Array a -> Int -> a -> Array a   

Inserts a new entry into an array.

Example call:
(update array idx val)
Parameters:
  • array : array to modify
  • idx : index of update
  • val : value to update at index idx Entries already initialized will be overwritten.

applyAt :: Array a -> Int -> (a -> a) -> Array a   

Applies a function to an element.

Example call:
(applyAt array idx fun)
Parameters:
  • array : array to modify
  • idx : index of update
  • fun : function to apply on element at index idx

(!) :: Array a -> Int -> a   

Yields the value at a given position.

Example call:
(a ! n)
Parameters:
  • a : array to look up in
  • n : index, where to look
Further infos:
  • defined as left-associative infix operator with precedence 9

listToDefaultArray :: (Int -> a) -> [a] -> Array a   

Creates a default array from a list of entries.

Example call:
(listToDefaultArray def xs)
Parameters:
  • def : default funtion for non-initialized indexes
  • xs : list of entries

listToErrorArray :: [a] -> Array a   

Creates an error array from a list of entries.

Example call:
(listToErrorArray xs)
Parameters:
  • xs : list of entries

combine :: (a -> b -> c) -> Array a -> Array b -> Array c   

combine two arbitrary arrays

combineSimilar :: (a -> a -> a) -> Array a -> Array a -> Array a   

the combination of two arrays with identical default function and a combinator which is neutral in the default can be implemented much more efficient