1 module ArrayStuff where
3 import Data.Array.IArray
5 funcArray lohi f = listArray lohi $ map f $ range lohi
7 constArray lohi v = listArray lohi $ repeat v
10 let swap (x, y) = (y, x) in
11 let (lo, hi) = bounds arr in
12 ixmap (swap lo, swap hi) swap arr
14 array2DtoListOfLists arr =
15 let ((xlo, ylo), (xhi, yhi)) = bounds arr in
16 map (\x -> map (\y -> arr ! (x, y)) $ range (ylo, yhi)) $ range (xlo, xhi)
18 -- Use instead of amap when the array implementation needs to change.
19 -- E.g., mapping an unboxed array to an array whose elements must be boxed.
20 amap2 f arr = funcArray (bounds arr) (\i -> f (arr ! i))
22 -- Like amap2 but the mapping function is also passed the index.
23 aixmap f arr = funcArray (bounds arr) (\i -> f i (arr ! i))