diff options
author | Austin Seipp <austin@well-typed.com> | 2014-12-03 12:44:03 -0600 |
---|---|---|
committer | Austin Seipp <austin@well-typed.com> | 2014-12-03 12:44:03 -0600 |
commit | 0c48e172836d6a1e281aed63e42d60063700e6d8 (patch) | |
tree | 89fe135e31e86dc579aba5652738f14c256a284d /compiler/utils/FiniteMap.hs | |
parent | b04296d3a3a256067787241a7727877e35e5af03 (diff) | |
download | haskell-0c48e172836d6a1e281aed63e42d60063700e6d8.tar.gz |
compiler: de-lhs utils/
Signed-off-by: Austin Seipp <austin@well-typed.com>
Diffstat (limited to 'compiler/utils/FiniteMap.hs')
-rw-r--r-- | compiler/utils/FiniteMap.hs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/compiler/utils/FiniteMap.hs b/compiler/utils/FiniteMap.hs new file mode 100644 index 0000000000..dccfca10a9 --- /dev/null +++ b/compiler/utils/FiniteMap.hs @@ -0,0 +1,29 @@ +-- Some extra functions to extend Data.Map + +module FiniteMap ( + insertList, + insertListWith, + deleteList, + foldRight, foldRightWithKey + ) where + +import Data.Map (Map) +import qualified Data.Map as Map + +insertList :: Ord key => [(key,elt)] -> Map key elt -> Map key elt +insertList xs m = foldl (\m (k, v) -> Map.insert k v m) m xs + +insertListWith :: Ord key + => (elt -> elt -> elt) + -> [(key,elt)] + -> Map key elt + -> Map key elt +insertListWith f xs m0 = foldl (\m (k, v) -> Map.insertWith f k v m) m0 xs + +deleteList :: Ord key => [key] -> Map key elt -> Map key elt +deleteList ks m = foldl (flip Map.delete) m ks + +foldRight :: (elt -> a -> a) -> a -> Map key elt -> a +foldRight = Map.fold +foldRightWithKey :: (key -> elt -> a -> a) -> a -> Map key elt -> a +foldRightWithKey = Map.foldrWithKey |