ZVON > References > Haskell reference
| Indexes | Syntax | Prelude | Ratio | Complex | Numeric | Ix | >> Array << | List | Maybe | Char | Monad | IO | Directory | System | Time | Locale | CPUTime | Random

Module: Array
Function: accumArray
Type: Ix a => (b -> c -> b) -> b -> (a,a) -> [(a,c)] -> Array a b
Description: relaxes the restriction that a given index may appear at most once in the association list, using an accumulating function which combines the values of associations with the same index. The first argument of accumArray is the accumulating function; the second is an initial value; the remaining two arguments are a bounds pair and an association list, as for the array function.
Related: array, listArray

Example 1

Input: accumArray (+) 0 (1,3) [(1,2),(1,4),(2,1),(2,2),(2,3),(3,5)]

Output: array (1,3) [(1,6),(2,6),(3,5)]

Example 2

Input: accumArray (++) "" (1,3) [(1,"H"),(3,"y"),(1,"i"),(2,","),(3,"ou")]

Output: array (1,3) [(1,"Hi"),(2,","),(3,"you")]

Example 3

Input: accumArray (\x y-> x ++ y ++ "-") "XXX:" (1,3) [(1,"H"),(3,"y"),(1,"i"),(2,","),(3,"ou")]

Output: array (1,3) [(1,"XXX:H-i-"),(2,"XXX:,-"),(3,"XXX:y-ou-")]