1 module ArrayStuff where
3 import Data.Array.IArray
5 funcArray lohi f = listArray lohi $ map f $ range lohi
8 let swap (x, y) = (y, x) in
9 let (lo, hi) = bounds arr in
10 ixmap (swap lo, swap hi) swap arr
12 array2DtoListOfLists arr =
13 let ((xlo, ylo), (xhi, yhi)) = bounds arr in
14 map (\x -> map (\y -> arr ! (x, y)) $ range (ylo, yhi)) $ range (xlo, xhi)
16 -- Use instead of amap when the array implementation needs to change.
17 -- E.g., mapping an unboxed array to an array whose elements must be boxed.
18 amap2 f arr = funcArray (bounds arr) (\i -> f (arr ! i))