From 5ae7be358daf169a3852d93f36c30c4ce7d0363e Mon Sep 17 00:00:00 2001 From: krasimir Date: Thu, 1 Jul 2010 08:51:59 +0000 Subject: redesign the open-literals API --- src/compiler/GF/Data/TrieMap.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/compiler/GF/Data') diff --git a/src/compiler/GF/Data/TrieMap.hs b/src/compiler/GF/Data/TrieMap.hs index a6749d641..a15c780ab 100644 --- a/src/compiler/GF/Data/TrieMap.hs +++ b/src/compiler/GF/Data/TrieMap.hs @@ -11,8 +11,8 @@ module GF.Data.TrieMap , insertWith - , unionWith - , unionsWith + , union, unionWith + , unions, unionsWith , elems ) where @@ -47,6 +47,9 @@ insertWith f (k:ks) v0 (Tr mb_v m) = case Map.lookup k m of Nothing -> Tr mb_v (Map.insert k (singleton ks v0) m) Just tr -> Tr mb_v (Map.insert k (insertWith f ks v0 tr) m) +union :: Ord k => TrieMap k v -> TrieMap k v -> TrieMap k v +union = unionWith (\a b -> a) + unionWith :: Ord k => (v -> v -> v) -> TrieMap k v -> TrieMap k v -> TrieMap k v unionWith f (Tr mb_v1 m1) (Tr mb_v2 m2) = let mb_v = case (mb_v1,mb_v2) of @@ -57,6 +60,9 @@ unionWith f (Tr mb_v1 m1) (Tr mb_v2 m2) = m = Map.unionWith (unionWith f) m1 m2 in Tr mb_v m +unions :: Ord k => [TrieMap k v] -> TrieMap k v +unions = foldl union empty + unionsWith :: Ord k => (v -> v -> v) -> [TrieMap k v] -> TrieMap k v unionsWith f = foldl (unionWith f) empty -- cgit v1.2.3