X-Git-Url: https://mattmccutchen.net/match/match.git/blobdiff_plain/967c39efa10c8a2d74812741cd7a2a96602a6210..08f65a95a67fa8835b97a387d9d1e285972ca22a:/program/ArrayStuff.hs diff --git a/program/ArrayStuff.hs b/program/ArrayStuff.hs index abf14c7..df0a969 100644 --- a/program/ArrayStuff.hs +++ b/program/ArrayStuff.hs @@ -4,6 +4,8 @@ import Data.Array.IArray funcArray lohi f = listArray lohi $ map f $ range lohi +constArray lohi v = listArray lohi $ repeat v + transposeArray arr = let swap (x, y) = (y, x) in let (lo, hi) = bounds arr in @@ -13,6 +15,12 @@ array2DtoListOfLists arr = let ((xlo, ylo), (xhi, yhi)) = bounds arr in map (\x -> map (\y -> arr ! (x, y)) $ range (ylo, yhi)) $ range (xlo, xhi) +listOfListsToArray2D ll = + listArray ((0, 0), (length ll - 1, length (head ll) - 1)) $ concat ll + -- Use instead of amap when the array implementation needs to change. -- E.g., mapping an unboxed array to an array whose elements must be boxed. amap2 f arr = funcArray (bounds arr) (\i -> f (arr ! i)) + +-- Like amap2 but the mapping function is also passed the index. +aixmap f arr = funcArray (bounds arr) (\i -> f i (arr ! i))