| 1 | module ArrayStuff where |
| 2 | import Data.Ix |
| 3 | import Data.Array.IArray |
| 4 | |
| 5 | funcArray lohi f = listArray lohi $ map f $ range lohi |
| 6 | |
| 7 | transposeArray arr = |
| 8 | let swap (x, y) = (y, x) in |
| 9 | let (lo, hi) = bounds arr in |
| 10 | ixmap (swap lo, swap hi) swap arr |
| 11 | |
| 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) |
| 15 | |
| 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)) |