Remove an unneeded forall.
[match/match.git] / program / ArrayStuff.hs
CommitLineData
967c39ef
MM
1module ArrayStuff where
2import Data.Ix
3import Data.Array.IArray
4
5funcArray lohi f = listArray lohi $ map f $ range lohi
6
7transposeArray 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
12array2DtoListOfLists 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.
18amap2 f arr = funcArray (bounds arr) (\i -> f (arr ! i))