/"      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~                                                  Safe-Inferred?Same as regular Haskell pairs, but (x :*: _|_) = (_|_ :*: y) =  _|_  portable provisionallibraries@haskell.org Trustworthy5A set of values a. O(n+m). See . O(1). Is this the empty set? O(1)%. The number of elements in the set. O(log n). Is the element in the set? O(log n)!. Is the element not in the set? O(log n)3. Find largest element smaller than the given one. ) lookupLT 3 (fromList [3, 5]) == Nothing ( lookupLT 5 (fromList [3, 5]) == Just 3 O(log n)4. Find smallest element greater than the given one. ( lookupGT 4 (fromList [3, 5]) == Just 5 ) lookupGT 5 (fromList [3, 5]) == Nothing O(log n):. Find largest element smaller or equal to the given one. ) lookupLE 2 (fromList [3, 5]) == Nothing ( lookupLE 4 (fromList [3, 5]) == Just 3 ( lookupLE 5 (fromList [3, 5]) == Just 5 O(log n);. Find smallest element greater or equal to the given one. ( lookupGE 3 (fromList [3, 5]) == Just 3 ( lookupGE 4 (fromList [3, 5]) == Just 5 ) lookupGE 6 (fromList [3, 5]) == Nothing O(1). The empty set. O(1). Create a singleton set. O(log n). Insert an element in a set. B If the set already contains an element equal to the given value, $ it is replaced with the new value. O(log n) . Delete an element from a set. O(n+m)9. Is this a proper subset? (ie. a subset but not equal). O(n+m). Is this a subset?  (s1  s2) tells whether s1 is a subset of s2. O(log n) . The minimal element of a set. O(log n) . The maximal element of a set. O(log n)H. Delete the minimal element. Returns an empty set if the set is empty. O(log n)H. Delete the maximal element. Returns an empty set if the set is empty. The union of a list of sets: ( ==    ). O(n+m)7. The union of two sets, preferring the first set when ! equal elements are encountered. ' The implementation uses the efficient  hedge-union algorithm. O(n+m). Difference of two sets. & The implementation uses an efficient hedge algorithm comparable with  hedge-union. O(n+m)<. The intersection of two sets. The implementation uses an  efficient hedge algorithm comparable with  hedge-union. Elements of the 0 result come from the first set, so for example   import qualified Data.Set as S  data AB = A | B deriving Show ( instance Ord AB where compare _ _ = EQ $ instance Eq AB where _ == _ = True = main = print (S.singleton A `S.intersection` S.singleton B, = S.singleton B `S.intersection` S.singleton A) prints  (fromList [A] ,fromList [B]). O(n)2. Filter all elements that satisfy the predicate. O(n)F. Partition the set into two sets, one with all elements that satisfy 1 the predicate and one with all elements that don't satisfy the predicate.  See also (.  O(n*log n).   f s! is the set obtained by applying f to each element of s. It'>s worth noting that the size of the result may be smaller if,  for some (x,y), x /= y && f x == f y O(n). The  f s ==  f s, but works only when f is monotonic.   The precondition is not checked.  Semi-formally, we have: . and [x < y ==> f x < f y | x <- ls, y <- ls] 5 ==> mapMonotonic f s == map f s  where ls = toList s O(n)A. Fold the elements in the set using the given right-associative 4 binary operator. This function is an equivalent of  and is present  for compatibility only. CPlease note that fold will be deprecated in the future and removed. O(n)A. Fold the elements in the set using the given right-associative  binary operator, such that  f z ==  f z . #.  For example, " toAscList set = foldr (:) [] set O(n). A strict version of &. Each application of the operator is A evaluated before using the result in the next application. This + function is strict in the starting value. O(n)@. Fold the elements in the set using the given left-associative  binary operator, such that  f z ==  f z . #.  For example, * toDescList set = foldl (flip (:)) [] set O(n). A strict version of &. Each application of the operator is A evaluated before using the result in the next application. This + function is strict in the starting value. !O(n). An alias of #,. The elements of a set in ascending order.  Subject to list fusion. "O(n)A. Convert the set to a list of elements. Subject to list fusion. #O(n)L. Convert the set to an ascending list of elements. Subject to list fusion. $O(n)D. Convert the set to a descending list of elements. Subject to list  fusion. % O(n*log n)(. Create a set from a list of elements. @If the elemens are ordered, linear-time implementation is used,  with the performance equal to '. &O(n)5. Build a set from an ascending list in linear time.  :The precondition (input list is ascending) is not checked. 'O(n)J. Build a set from an ascending list of distinct elements in linear time.  CThe precondition (input list is strictly ascending) is not checked. (O(log n). The expression (( x set ) is a pair  (set1,set2)  where set1 comprises the elements of set less than x and set2  comprises the elements of set greater than x. )O(log n) . Performs a ($ but also returns whether the pivot ( element was found in the original set. *O(log n) . Return the index( of an element, which is its zero-based F index in the sorted sequence of elements. The index is a number from 0 up  to, but not including, the  of the set. Calls  when the element  is not a  of the set. B findIndex 2 (fromList [5,3]) Error: element is not in the set # findIndex 3 (fromList [5,3]) == 0 # findIndex 5 (fromList [5,3]) == 1 B findIndex 6 (fromList [5,3]) Error: element is not in the set +O(log n) . Lookup the index1 of an element, which is its zero-based index in = the sorted sequence of elements. The index is a number from 0 up to, but not  including, the  of the set. 4 isJust (lookupIndex 2 (fromList [5,3])) == False 0 fromJust (lookupIndex 3 (fromList [5,3])) == 0 0 fromJust (lookupIndex 5 (fromList [5,3])) == 1 4 isJust (lookupIndex 6 (fromList [5,3])) == False ,O(log n). Retrieve an element by its index, i.e. by its zero-based 2 index in the sorted sequence of elements. If the index is out of range (less  than zero, greater or equal to  of the set),  is called.  elemAt 0 (fromList [5,3]) == 3  elemAt 1 (fromList [5,3]) == 5 8 elemAt 2 (fromList [5,3]) Error: index out of range -O(log n). Delete the element at index", i.e. by its zero-based index in ) the sorted sequence of elements. If the index" is out of range (less than zero,  greater or equal to  of the set),  is called. / deleteAt 0 (fromList [5,3]) == singleton 5 / deleteAt 1 (fromList [5,3]) == singleton 3 = deleteAt 2 (fromList [5,3]) Error: index out of range = deleteAt (-1) (fromList [5,3]) Error: index out of range .O(log n)'. Delete and find the minimal element. 2 deleteFindMin set = (findMin set, deleteMin set) /O(log n)'. Delete and find the maximal element. 2 deleteFindMax set = (findMax set, deleteMax set) 0O(log n)4. Retrieves the minimal key of the set, and the set  stripped of that element, or  if passed an empty set. 1O(log n)4. Retrieves the maximal key of the set, and the set  stripped of that element, or  if passed an empty set. 2O(n);. Show the tree that implements the set. The tree is shown " in a compressed, hanging format. 3O(n). The expression (showTreeWith hang wide map) shows & the tree that implements the set. If hang is  True, a hanging5 tree is shown otherwise a rotated tree is shown. If  wide is ", an extra wide version is shown. F Set> putStrLn $ showTreeWith True False $ fromDistinctAscList [1..5]  4  +--2  | +--1  | +--3  +--5  E Set> putStrLn $ showTreeWith True True $ fromDistinctAscList [1..5]  4  |  +--2  | |  | +--1  | |  | +--3  |  +--5  F Set> putStrLn $ showTreeWith False True $ fromDistinctAscList [1..5]  +--5  |  4  |  | +--3  | |  +--2  |  +--1 4O(n)/. Test if the internal set structure is valid. d       !"#$%&'()*+,-./01 !23"#$%&'(4)*+,-./0123;    !"#$%&'()*+,-./01 234*`       !"#$%&'()*+,-./01 !23"#$%&'(4)*+,-./0123portable provisionallibraries@haskell.org Trustworthym5A Map from keys k to values a. 6O(log n). Find the value at a key.  Calls $ when the element can not be found. B fromList [(5,'a'), (3,'b')] ! 1 Error: element not in the map ( fromList [(5,'a'), (3,'b')] ! 5 == 'a' 7Same as e. 8O(1). Is the map empty? ) Data.Map.null (empty) == True * Data.Map.null (singleton 1 'a') == False 9O(1)%. The number of elements in the map. 3 size empty == 0 3 size (singleton 1 'a') == 1 3 size (fromList([(1,'a'), (2,'c'), (3,'b')])) == 3 :O(log n)(. Lookup the value at a key in the map. 4The function will return the corresponding value as (4 value),  or  if the key isn't in the map. An example of using lookup:   import Prelude hiding (lookup)  import Data.Map  ; employeeDept = fromList([("John","Sales"), ("Bob","IT")]) < deptCountry = fromList([("IT","USA"), ("Sales","France")]) E countryCurrency = fromList([("USA", "Dollar"), ("France", "Euro")])  , employeeCurrency :: String -> Maybe String  employeeCurrency name = do & dept <- lookup name employeeDept ( country <- lookup dept deptCountry $ lookup country countryCurrency   main = do H putStrLn $ "John's currency: " ++ (show (employeeCurrency "John")) H putStrLn $ "Pete's currency: " ++ (show (employeeCurrency "Pete")) The output of this program:  John's currency: Just "Euro"  Pete's currency: Nothing ;O(log n)+. Is the key a member of the map? See also <. 0 member 5 (fromList [(5,'a'), (3,'b')]) == True 1 member 1 (fromList [(5,'a'), (3,'b')]) == False <O(log n)/. Is the key not a member of the map? See also ;. 4 notMember 5 (fromList [(5,'a'), (3,'b')]) == False 3 notMember 1 (fromList [(5,'a'), (3,'b')]) == True 5O(log n). Find the value at a key.  Calls $ when the element can not be found. =O(log n). The expression (= def k map) returns  the value at key k or returns default value def ! when the key is not in the map. < findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x' < findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a' >O(log n)=. Find largest key smaller than the given one and return the " corresponding (key, value) pair. 5 lookupLT 3 (fromList [(3,'a'), (5,'b')]) == Nothing ; lookupLT 4 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a') ?O(log n)>. Find smallest key greater than the given one and return the " corresponding (key, value) pair. ; lookupGT 4 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b') 5 lookupGT 5 (fromList [(3,'a'), (5,'b')]) == Nothing @O(log n)@. Find largest key smaller or equal to the given one and return & the corresponding (key, value) pair. 5 lookupLE 2 (fromList [(3,'a'), (5,'b')]) == Nothing ; lookupLE 4 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a') ; lookupLE 5 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b') AO(log n)A. Find smallest key greater or equal to the given one and return & the corresponding (key, value) pair. ; lookupGE 3 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a') ; lookupGE 4 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b') 5 lookupGE 6 (fromList [(3,'a'), (5,'b')]) == Nothing BO(1). The empty map.  empty == fromList []  size empty == 0 CO(1). A map with a single element. / singleton 1 'a' == fromList [(1, 'a')]  size (singleton 1 'a') == 1 DO(log n)). Insert a new key and value in the map. C If the key is already present in the map, the associated value is # replaced with the supplied value. D is equivalent to  E 6. M insert 5 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'x')] W insert 7 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'a'), (7, 'x')] ? insert 5 'x' empty == singleton 5 'x' EO(log n)=. Insert with a function, combining new value and old value.  E f key value mp ( will insert the pair (key, value) into mp if key does @ not exist in the map. If the key does exist, the function will  insert the pair (key, f new_value old_value). [ insertWith (++) 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "xxxa")] d insertWith (++) 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] L insertWith (++) 5 "xxx" empty == singleton 5 "xxx" FO(log n)B. Insert with a function, combining key, new value and old value.  F f key value mp ( will insert the pair (key, value) into mp if key does @ not exist in the map. If the key does exist, the function will  insert the pair (key,f key new_value old_value). 9 Note that the key passed to f is the same key passed to F. T let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value ^ insertWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:xxx|a")] d insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] L insertWithKey f 5 "xxx" empty == singleton 5 "xxx" GO(log n)6. Combines insert operation with old value retrieval.  The expression (G f k x map) 0 is a pair where the first element is equal to (: k map) " and the second element equal to (F f k x map).  T let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value p insertLookupWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:xxx|a")]) v insertLookupWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "xxx")]) ^ insertLookupWithKey f 5 "xxx" empty == (Nothing, singleton 5 "xxx") This is how to define  insertLookup using insertLookupWithKey: D let insertLookup kx x t = insertLookupWithKey (\_ a _ -> a) kx x t _ insertLookup 5 "x" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "x")]) i insertLookup 7 "x" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "x")]) HO(log n)?. Delete a key and its value from the map. When the key is not 4 a member of the map, the original map is returned. ; delete 5 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" I delete 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] 1 delete 5 empty == empty IO(log n)M. Update a value at a specific key with the result of the provided function.  When the key is not 4 a member of the map, the original map is returned. Y adjust ("new " ++) 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")] U adjust ("new " ++) 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] = adjust ("new " ++) 7 empty == empty JO(log n)8. Adjust a value at a specific key. When the key is not 4 a member of the map, the original map is returned. * let f key x = (show key) ++ ":new " ++ x X adjustWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] R adjustWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] : adjustWithKey f 7 empty == empty KO(log n). The expression (K f k map) updates the value x  at k (if it is in the map). If (f x) is , the element is  deleted. If it is (4 y ), the key k is bound to the new value y. 6 let f x = if x == "a" then Just "new a" else Nothing O update f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")] K update f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] = update f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" LO(log n). The expression (L f k map) updates the  value x at k (if it is in the map). If (f k x) is , # the element is deleted. If it is (4 y ), the key k is bound  to the new value y. G let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing X updateWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] R updateWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] D updateWithKey f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" MO(log n). Lookup and update. See also L. 7 The function returns changed value, if it is updated. = Returns the original key value if the map entry is deleted. G let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing p updateLookupWithKey f 5 (fromList [(5,"a"), (3,"b")]) == (Just "5:new a", fromList [(3, "b"), (5, "5:new a")]) d updateLookupWithKey f 7 (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a")]) V updateLookupWithKey f 3 (fromList [(5,"a"), (3,"b")]) == (Just "b", singleton 5 "a") NO(log n). The expression (N f k map) alters the value x at k, or absence thereof.  N7 can be used to insert, delete, or update a value in a 5.  In short : : k (N f k m) = f (: k m).  let f _ = Nothing J alter f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] < alter f 5 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"   let f _ = Just "c" T alter f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "c")] J alter f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "c")] OO(log n) . Return the index, of a key, which is its zero-based index in 9 the sequence sorted by keys. The index is a number from 0 up to, but not  including, the 9 of the map. Calls  when the key is not  a ; of the map. O findIndex 2 (fromList [(5,"a"), (3,"b")]) Error: element is not in the map 0 findIndex 3 (fromList [(5,"a"), (3,"b")]) == 0 0 findIndex 5 (fromList [(5,"a"), (3,"b")]) == 1 O findIndex 6 (fromList [(5,"a"), (3,"b")]) Error: element is not in the map PO(log n) . Lookup the index, of a key, which is its zero-based index in 9 the sequence sorted by keys. The index is a number from 0 up to, but not  including, the 9 of the map. A isJust (lookupIndex 2 (fromList [(5,"a"), (3,"b")])) == False = fromJust (lookupIndex 3 (fromList [(5,"a"), (3,"b")])) == 0 = fromJust (lookupIndex 5 (fromList [(5,"a"), (3,"b")])) == 1 A isJust (lookupIndex 6 (fromList [(5,"a"), (3,"b")])) == False QO(log n). Retrieve an element by its index, i.e. by its zero-based . index in the sequence sorted by keys. If the index is out of range (less  than zero, greater or equal to 9 of the map),  is called. 3 elemAt 0 (fromList [(5,"a"), (3,"b")]) == (3,"b") 4 elemAt 1 (fromList [(5,"a"), (3,"b")]) == (5, "a") E elemAt 2 (fromList [(5,"a"), (3,"b")]) Error: index out of range RO(log n). Update the element at index", i.e. by its zero-based index in % the sequence sorted by keys. If the index" is out of range (less than zero,  greater or equal to 9 of the map),  is called. b updateAt (\ _ _ -> Just "x") 0 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "x"), (5, "a")] b updateAt (\ _ _ -> Just "x") 1 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "x")] ^ updateAt (\ _ _ -> Just "x") 2 (fromList [(5,"a"), (3,"b")]) Error: index out of range ^ updateAt (\ _ _ -> Just "x") (-1) (fromList [(5,"a"), (3,"b")]) Error: index out of range T updateAt (\_ _ -> Nothing) 0 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" T updateAt (\_ _ -> Nothing) 1 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" ^ updateAt (\_ _ -> Nothing) 2 (fromList [(5,"a"), (3,"b")]) Error: index out of range ^ updateAt (\_ _ -> Nothing) (-1) (fromList [(5,"a"), (3,"b")]) Error: index out of range SO(log n). Delete the element at index", i.e. by its zero-based index in % the sequence sorted by keys. If the index" is out of range (less than zero,  greater or equal to 9 of the map),  is called. > deleteAt 0 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" > deleteAt 1 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" H deleteAt 2 (fromList [(5,"a"), (3,"b")]) Error: index out of range H deleteAt (-1) (fromList [(5,"a"), (3,"b")]) Error: index out of range TO(log n)$. The minimal key of the map. Calls  if the map is empty. 2 findMin (fromList [(5,"a"), (3,"b")]) == (3,"b") R findMin empty Error: empty map has no minimal element UO(log n)$. The maximal key of the map. Calls  if the map is empty. 2 findMax (fromList [(5,"a"), (3,"b")]) == (5,"a") R findMax empty Error: empty map has no maximal element VO(log n)D. Delete the minimal key. Returns an empty map if the map is empty. Q deleteMin (fromList [(5,"a"), (3,"b"), (7,"c")]) == fromList [(5,"a"), (7,"c")]  deleteMin empty == empty WO(log n)D. Delete the maximal key. Returns an empty map if the map is empty. Q deleteMax (fromList [(5,"a"), (3,"b"), (7,"c")]) == fromList [(3,"b"), (5,"a")]  deleteMax empty == empty XO(log n)'. Update the value at the minimal key. d updateMin (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "Xb"), (5, "a")] U updateMin (\ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" YO(log n)'. Update the value at the maximal key. d updateMax (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "Xa")] U updateMax (\ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" ZO(log n)'. Update the value at the minimal key. x updateMinWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"3:b"), (5,"a")] j updateMinWithKey (\ _ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" [O(log n)'. Update the value at the maximal key. x updateMaxWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"b"), (5,"5:a")] j updateMaxWithKey (\ _ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" \O(log n)9. Retrieves the minimal (key,value) pair of the map, and & the map stripped of that element, or  if passed an empty map. Q minViewWithKey (fromList [(5,"a"), (3,"b")]) == Just ((3,"b"), singleton 5 "a") ! minViewWithKey empty == Nothing ]O(log n)9. Retrieves the maximal (key,value) pair of the map, and & the map stripped of that element, or  if passed an empty map. Q maxViewWithKey (fromList [(5,"a"), (3,"b")]) == Just ((5,"a"), singleton 3 "b") ! maxViewWithKey empty == Nothing ^O(log n)9. Retrieves the value associated with minimal key of the / map, and the map stripped of that element, or  if passed an  empty map. F minView (fromList [(5,"a"), (3,"b")]) == Just ("b", singleton 5 "a")  minView empty == Nothing _O(log n)9. Retrieves the value associated with maximal key of the / map, and the map stripped of that element, or  if passed an F maxView (fromList [(5,"a"), (3,"b")]) == Just ("a", singleton 3 "b")  maxView empty == Nothing `The union of a list of maps:  (` ==  b B). n unions [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])] 0 == fromList [(3, "b"), (5, "a"), (7, "C")] n unions [(fromList [(5, "A3"), (3, "B3")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "a"), (3, "b")])] 2 == fromList [(3, "B3"), (5, "A3"), (7, "C")] a9The union of a list of maps, with a combining operation:  (a f ==  (c f) B). w unionsWith (++) [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])] 5 == fromList [(3, "bB3"), (5, "aAA3"), (7, "C")] bO(n+m).  The expression (b t1 t2!) takes the left-biased union of t1 and t2.  It prefers t1& when duplicate keys are encountered,  i.e. (b == c 6). ' The implementation uses the efficient  hedge-union algorithm. r union (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "a"), (7, "C")] cO(n+m)I. Union with a combining function. The implementation uses the efficient  hedge-union algorithm. | unionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "aA"), (7, "C")] dO(n+m). H Union with a combining function. The implementation uses the efficient  hedge-union algorithm. Z let f key left_value right_value = (show key) ++ ":" ++ left_value ++ "|" ++ right_value  unionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "5:a|A"), (7, "C")] eO(n+m). Difference of two maps. B Return elements of the first map not existing in the second map. & The implementation uses an efficient hedge algorithm comparable with  hedge-union. _ difference (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 3 "b" fO(n+m)(. Difference with a combining function.  When two equal keys are M encountered, the combining function is applied to the values of these keys.  If it returns 7, the element is discarded (proper set difference). If  it returns (4 y+), the element is updated with a new value y. & The implementation uses an efficient hedge algorithm comparable with  hedge-union. E let f al ar = if al == "b" then Just (al ++ ":" ++ ar) else Nothing \ differenceWith f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (7, "C")])  == singleton 3 "b:B" gO(n+m)@. Difference with a combining function. When two equal keys are L encountered, the combining function is applied to the key and both values.  If it returns 7, the element is discarded (proper set difference). If  it returns (4 y+), the element is updated with a new value y. & The implementation uses an efficient hedge algorithm comparable with  hedge-union. Z let f k al ar = if al == "b" then Just ((show k) ++ ":" ++ al ++ "|" ++ ar) else Nothing ` differenceWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (10, "C")])  == singleton 3 "3:b|B" hO(n+m). Intersection of two maps. B Return data in the first map for the keys existing in both maps.  (h m1 m2 == i 6 m1 m2). & The implementation uses an efficient hedge algorithm comparable with   hedge-union. a intersection (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "a" iO(n+m)C. Intersection with a combining function. The implementation uses  an efficient hedge algorithm comparable with  hedge-union. k intersectionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "aA" jO(n+m)C. Intersection with a combining function. The implementation uses  an efficient hedge algorithm comparable with  hedge-union. 4 let f k al ar = (show k) ++ ":" ++ al ++ "|" ++ ar n intersectionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "5:a|A" kO(n+m)A. A high-performance universal combining function. This function  is used to define c, d, f,  g, i, j and can be 0 used to define other custom combine functions. 6Please make sure you know what is going on when using k, B otherwise you can be surprised by unexpected code growth or even # corruption of the data structure. When k5 is given three arguments, it is inlined to the call  site. You should therefore use k only to define your custom 4 combining functions. For example, you could define d,  g and j as  R myUnionWithKey f m1 m2 = mergeWithKey (\k x1 x2 -> Just (f k x1 x2)) id id m1 m2 E myDifferenceWithKey f m1 m2 = mergeWithKey f id (const empty) m1 m2 o myIntersectionWithKey f m1 m2 = mergeWithKey (\k x1 x2 -> Just (f k x1 x2)) (const empty) (const empty) m1 m2  When calling k combine only1 only2, a function combining two  IntMaps is created, such that H if a key is present in both maps, it is passed with both corresponding  values to the combine6 function. Depending on the result, the key is either ? present in the result with specified value, or is left out; ? a nonempty subtree present only in the first map is passed to only1 and & the output is added to the result; @ a nonempty subtree present only in the second map is passed to only2 and & the output is added to the result. The only1 and only2 methods Mmust return a map with a subset (possibly empty) of the keys of the given map. A The values can be modified arbitrarily. Most common variants of only1 and  only2 are 7 and 6 B, but for example x f or  q f could be used for any f. lO(n+m).  This function is defined as (l = m (==)). mO(n+m).  The expression (m f t1 t2 ) returns  if  all keys in t1 are in tree t2 , and when f returns  when @ applied to their respective values. For example, the following  expressions are all :  E isSubmapOfBy (==) (fromList [('a',1)]) (fromList [('a',1),('b',2)]) E isSubmapOfBy (<=) (fromList [('a',1)]) (fromList [('a',1),('b',2)]) M isSubmapOfBy (==) (fromList [('a',1),('b',2)]) (fromList [('a',1),('b',2)]) But the following are all 8: E isSubmapOfBy (==) (fromList [('a',2)]) (fromList [('a',1),('b',2)]) E isSubmapOfBy (<) (fromList [('a',1)]) (fromList [('a',1),('b',2)]) E isSubmapOfBy (==) (fromList [('a',1),('b',2)]) (fromList [('a',1)]) nO(n+m)9. Is this a proper submap? (ie. a submap but not equal).  Defined as (n = o (==)). oO(n+m)9. Is this a proper submap? (ie. a submap but not equal).  The expression (o f m1 m2 ) returns  when  m1 and m2 are not equal,  all keys in m1 are in m2 , and when f returns  when @ applied to their respective values. For example, the following  expressions are all :  E isProperSubmapOfBy (==) (fromList [(1,1)]) (fromList [(1,1),(2,2)]) E isProperSubmapOfBy (<=) (fromList [(1,1)]) (fromList [(1,1),(2,2)]) But the following are all 8: K isProperSubmapOfBy (==) (fromList [(1,1),(2,2)]) (fromList [(1,1),(2,2)]) E isProperSubmapOfBy (==) (fromList [(1,1),(2,2)]) (fromList [(1,1)]) K isProperSubmapOfBy (<) (fromList [(1,1)]) (fromList [(1,1),(2,2)]) pO(n)0. Filter all values that satisfy the predicate. A filter (> "a") (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" 7 filter (> "x") (fromList [(5,"a"), (3,"b")]) == empty 7 filter (< "a") (fromList [(5,"a"), (3,"b")]) == empty qO(n). Filter all keys/#values that satisfy the predicate. P filterWithKey (\k _ -> k > 4) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" rO(n)8. Partition the map according to a predicate. The first F map contains all elements that satisfy the predicate, the second all , elements that fail the predicate. See also . W partition (> "a") (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", singleton 5 "a") [ partition (< "x") (fromList [(5,"a"), (3,"b")]) == (fromList [(3, "b"), (5, "a")], empty) [ partition (> "x") (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3, "b"), (5, "a")]) sO(n)8. Partition the map according to a predicate. The first F map contains all elements that satisfy the predicate, the second all , elements that fail the predicate. See also . g partitionWithKey (\ k _ -> k > 3) (fromList [(5,"a"), (3,"b")]) == (singleton 5 "a", singleton 3 "b") k partitionWithKey (\ k _ -> k < 7) (fromList [(5,"a"), (3,"b")]) == (fromList [(3, "b"), (5, "a")], empty) k partitionWithKey (\ k _ -> k > 7) (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3, "b"), (5, "a")]) tO(n). Map values and collect the 4 results. 6 let f x = if x == "a" then Just "new a" else Nothing A mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a" uO(n) . Map keys/values and collect the 4 results. D let f k _ = if k < 5 then Just ("key : " ++ (show k)) else Nothing J mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key : 3" vO(n). Map values and separate the 9 and : results. / let f a = if a < "c" then Left a else Right a = mapEither f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) C == (fromList [(3,"b"), (5,"a")], fromList [(1,"x"), (7,"z")])  L mapEither (\ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) ? == (empty, fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) wO(n) . Map keys/values and separate the 9 and : results. < let f k a = if k < 5 then Left (k * 2) else Right (a ++ a) D mapEitherWithKey f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) A == (fromList [(1,2), (3,6)], fromList [(5,"aa"), (7,"zz")])  T mapEitherWithKey (\_ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) ? == (empty, fromList [(1,"x"), (3,"b"), (5,"a"), (7,"z")]) xO(n)-. Map a function over all values in the map. O map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")] yO(n)-. Map a function over all values in the map. & let f key x = (show key) ++ ":" ++ x Q mapWithKey f (fromList [(5,"a"), (3,"b")]) == fromList [(3, "3:b"), (5, "5:a")] zO(n).  z f s ==   $ ; ((k, v) -> (,) k  $ f k v) ( m) ) That is, behaves exactly like a regular ; except that the traversing > function also has access to the key associated with a value.  traverseWithKey (\k v -> if odd k then Just (succ v) else Nothing) (fromList [(1, 'a'), (5, 'e')]) == Just (fromList [(1, 'b'), (5, 'f')]) o traverseWithKey (\k v -> if odd k then Just (succ v) else Nothing) (fromList [(2, 'c')]) == Nothing {O(n). The function { threads an accumulating 6 argument through the map in ascending order of keys.  let f a b = (a ++ b, b ++ "X") p mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")]) |O(n). The function | threads an accumulating 6 argument through the map in ascending order of keys. < let f a k b = (a ++ " " ++ (show k) ++ "-" ++ b, b ++ "X") { mapAccumWithKey f "Everything:" (fromList [(5,"a"), (3,"b")]) == ("Everything: 3-b 5-a", fromList [(3, "bX"), (5, "aX")]) <O(n). The function < threads an accumulating 6 argument through the map in ascending order of keys. }O(n). The function  mapAccumR threads an accumulating 7 argument through the map in descending order of keys. ~ O(n*log n).  ~ f s! is the map obtained by applying f to each key of s. )The size of the result may be smaller if f maps two or more distinct J keys to the same new key. In this case the value at the greatest of the  original keys is retained. e mapKeys (+ 1) (fromList [(5,"a"), (3,"b")]) == fromList [(4, "b"), (6, "a")] W mapKeys (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "c" W mapKeys (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "c"  O(n*log n).   c f s! is the map obtained by applying f to each key of s. )The size of the result may be smaller if f maps two or more distinct G keys to the same new key. In this case the associated values will be  combined using c. c mapKeysWith (++) (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "cdab" c mapKeysWith (++) (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "cdab" O(n).   f s == ~ f s, but works only when f  is strictly monotonic.  That is, for any values x and y, if x < y then f x < f y.   The precondition is not checked.  Semi-formally, we have:  . and [x < y ==> f x < f y | x <- ls, y <- ls] = ==> mapKeysMonotonic f s == mapKeys f s  where ls = keys s This means that f9 maps distinct original keys to distinct resulting keys. + This function has better performance than ~. a mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")]) == fromList [(6, "b"), (10, "a")] O valid (mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")])) == True P valid (mapKeysMonotonic (\ _ -> 1) (fromList [(5,"a"), (3,"b")])) == False O(n)?. Fold the values in the map using the given right-associative  binary operator, such that  f z ==  f z . .  For example,   elems map = foldr (:) [] map  let f a len = len + (length a) 0 foldr f 0 (fromList [(5,"a"), (3,"bbb")]) == 4 O(n). A strict version of &. Each application of the operator is A evaluated before using the result in the next application. This + function is strict in the starting value. O(n)>. Fold the values in the map using the given left-associative  binary operator, such that  f z ==  f z . .  For example,  ' elems = reverse . foldl (flip (:)) []  let f len a = len + (length a) 0 foldl f 0 (fromList [(5,"a"), (3,"bbb")]) == 4 O(n). A strict version of &. Each application of the operator is A evaluated before using the result in the next application. This + function is strict in the starting value. O(n)H. Fold the keys and values in the map using the given right-associative  binary operator, such that   f z ==  (= f) z . .  For example,  2 keys map = foldrWithKey (\k x ks -> k:ks) [] map A let f k a result = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")" K foldrWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (5:a)(3:b)" O(n). A strict version of &. Each application of the operator is A evaluated before using the result in the next application. This + function is strict in the starting value. O(n)G. Fold the keys and values in the map using the given left-associative  binary operator, such that   f z ==  (\z' (kx, x) -> f z' kx x) z . .  For example,  4 keys = reverse . foldlWithKey (\ks k x -> k:ks) [] A let f result k a = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")" K foldlWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (3:b)(5:a)" O(n). A strict version of &. Each application of the operator is A evaluated before using the result in the next application. This + function is strict in the starting value. O(n). F Return all elements of the map in the ascending order of their keys.  Subject to list fusion. 2 elems (fromList [(5,"a"), (3,"b")]) == ["b","a"]  elems empty == [] O(n)A. Return all keys of the map in ascending order. Subject to list  fusion. - keys (fromList [(5,"a"), (3,"b")]) == [3,5]  keys empty == [] O(n). An alias for . Return all key/value pairs in the map 1 in ascending key order. Subject to list fusion. < assocs (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]  assocs empty == [] O(n)". The set of all keys of the map. B keysSet (fromList [(5,"a"), (3,"b")]) == Data.Set.fromList [3,5] ! keysSet empty == Data.Set.empty O(n)C. Build a map from a set of keys and a function which for each key  computes its value. a fromSet (\k -> replicate k 'a') (Data.Set.fromList [3, 5]) == fromList [(5,"aaaaa"), (3,"aaa")] + fromSet undefined Data.Set.empty == empty  O(n*log n) . Build a map from a list of key/value pairs. See also . K If the list contains more than one value for the same key, the last value  for the key is retained. IIf the keys of the list are ordered, linear-time implementation is used,  with the performance equal to .  fromList [] == empty F fromList [(5,"a"), (3,"b"), (5, "c")] == fromList [(5,"c"), (3,"b")] F fromList [(5,"c"), (3,"b"), (5, "a")] == fromList [(5,"a"), (3,"b")]  O(n*log n) . Build a map from a list of key/0value pairs with a combining function. See also . e fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "ab"), (5, "aba")]  fromListWith (++) [] == empty  O(n*log n) . Build a map from a list of key/0value pairs with a combining function. See also . & let f k a1 a2 = (show k) ++ a1 ++ a2 h fromListWithKey f [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "3ab"), (5, "5a5ba")]  fromListWithKey f [] == empty O(n)". Convert the map to a list of key/%value pairs. Subject to list fusion. < toList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]  toList empty == [] O(n)". Convert the map to a list of key/value pairs where the keys are - in ascending order. Subject to list fusion. ? toAscList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")] O(n)". Convert the map to a list of key/value pairs where the keys 2 are in descending order. Subject to list fusion. @ toDescList (fromList [(5,"a"), (3,"b")]) == [(5,"a"), (3,"b")] O(n)5. Build a map from an ascending list in linear time.  :The precondition (input list is ascending) is not checked. J fromAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")] J fromAscList [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "b")] 9 valid (fromAscList [(3,"b"), (5,"a"), (5,"b")]) == True : valid (fromAscList [(5,"a"), (3,"b"), (5,"b")]) == False O(n)^. Build a map from an ascending list in linear time with a combining function for equal keys.  :The precondition (input list is ascending) is not checked. T fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "ba")] B valid (fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")]) == True C valid (fromAscListWith (++) [(5,"a"), (3,"b"), (5,"b")]) == False O(n);. Build a map from an ascending list in linear time with a $ combining function for equal keys.  :The precondition (input list is ascending) is not checked. - let f k a1 a2 = (show k) ++ ":" ++ a1 ++ a2 b fromAscListWithKey f [(3,"b"), (5,"a"), (5,"b"), (5,"b")] == fromList [(3, "b"), (5, "5:b5:ba")] K valid (fromAscListWithKey f [(3,"b"), (5,"a"), (5,"b"), (5,"b")]) == True L valid (fromAscListWithKey f [(5,"a"), (3,"b"), (5,"b"), (5,"b")]) == False O(n)J. Build a map from an ascending list of distinct elements in linear time.   The precondition is not checked. I fromDistinctAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")] A valid (fromDistinctAscList [(3,"b"), (5,"a")]) == True B valid (fromDistinctAscList [(3,"b"), (5,"a"), (5,"b")]) == False O(log n). The expression ( k map ) is a pair  (map1,map2) where  the keys in map1 are smaller than k and the keys in map2 larger than k.  Any key equal to k is found in neither map1 nor map2. O split 2 (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3,"b"), (5,"a")]) C split 3 (fromList [(5,"a"), (3,"b")]) == (empty, singleton 5 "a") M split 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", singleton 5 "a") C split 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", empty) O split 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], empty) O(log n). The expression ( k map) splits a map just  like  but also returns : k map. ^ splitLookup 2 (fromList [(5,"a"), (3,"b")]) == (empty, Nothing, fromList [(3,"b"), (5,"a")]) S splitLookup 3 (fromList [(5,"a"), (3,"b")]) == (empty, Just "b", singleton 5 "a") \ splitLookup 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Nothing, singleton 5 "a") S splitLookup 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Just "a", empty) ^ splitLookup 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], Nothing, empty) O(log n)'. Delete and find the minimal element. a deleteFindMin (fromList [(5,"a"), (3,"b"), (10,"c")]) == ((3,"b"), fromList[(5,"a"), (10,"c")]) t deleteFindMin Error: can not return the minimal element of an empty map O(log n)'. Delete and find the maximal element. b deleteFindMax (fromList [(5,"a"), (3,"b"), (10,"c")]) == ((10,"c"), fromList [(3,"b"), (5,"a")]) t deleteFindMax empty Error: can not return the maximal element of an empty map O(n);. Show the tree that implements the map. The tree is shown & in a compressed, hanging format. See . O(n). The expression ( showelem hang wide map) shows @ the tree that implements the map. Elements are shown using the showElem function. If hang is  , a hanging5 tree is shown otherwise a rotated tree is shown. If  wide is ", an extra wide version is shown. : Map> let t = fromDistinctAscList [(x,()) | x <- [1..5]] A Map> putStrLn $ showTreeWith (\k x -> show (k,x)) True False t  (4,())  +--(2,())  | +--(1,())  | +--(3,())  +--(5,())  @ Map> putStrLn $ showTreeWith (\k x -> show (k,x)) True True t  (4,())  |  +--(2,())  | |  | +--(1,())  | |  | +--(3,())  |  +--(5,())  A Map> putStrLn $ showTreeWith (\k x -> show (k,x)) False True t  +--(5,())  |  (4,())  |  | +--(3,())  | |  +--(2,())  |  +--(1,()) O(n)/. Test if the internal map structure is valid. 0 valid (fromAscList [(3,"b"), (5,"a")]) == True 1 valid (fromAscList [(5,"a"), (3,"b")]) == False >Exported only for Debug.QuickCheck ?@AB5CD67EF89:;<5=>?@ABCDGEFGHIJKLMNOPQRSTUVWXYZ[\]^_H`abIcdeJfghKijklmLnopqrstuvwxyz{|<}~MNOPQRSTUVWXYZ[\]^_`abcde>fghijklmnopq~?@A5CD6789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~OPQRSTVWXZ[\]>g?A@B5DC67EF89:;<5=>?@ABCDGEFGHIJKLMNOPQRSTUVWXYZ[\]^_H`abIcdeJfghKijklmLnopqrstuvwxyz{|<}~MNOPQRSTUVWXYZ[\]^_`abcde>fghijklmnopqportable provisionallibraries@haskell.orgSafej56789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~j56789;<:=>?@ABCDEFGHIJKLMNbcd`aefghijkxyz{|}~pqrstuvwlmnoPOQRSTUVWXYZ[^_\]portable provisionallibraries@haskell.orgSafe,O(log n). The expression ( def k map) returns  the value at key k or returns default value def ! when the key is not in the map. < findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x' < findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a' O(1). A map with a single element. / singleton 1 'a' == fromList [(1, 'a')]  size (singleton 1 'a') == 1 O(log n)). Insert a new key and value in the map. C If the key is already present in the map, the associated value is # replaced with the supplied value.  is equivalent to   6. M insert 5 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'x')] W insert 7 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'a'), (7, 'x')] ? insert 5 'x' empty == singleton 5 'x' O(log n)=. Insert with a function, combining new value and old value.   f key value mp ( will insert the pair (key, value) into mp if key does @ not exist in the map. If the key does exist, the function will  insert the pair (key, f new_value old_value). [ insertWith (++) 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "xxxa")] d insertWith (++) 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] L insertWith (++) 5 "xxx" empty == singleton 5 "xxx" O(log n)B. Insert with a function, combining key, new value and old value.   f key value mp ( will insert the pair (key, value) into mp if key does @ not exist in the map. If the key does exist, the function will  insert the pair (key,f key new_value old_value). 9 Note that the key passed to f is the same key passed to . T let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value ^ insertWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:xxx|a")] d insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] L insertWithKey f 5 "xxx" empty == singleton 5 "xxx" O(log n)6. Combines insert operation with old value retrieval.  The expression ( f k x map) 0 is a pair where the first element is equal to (: k map) " and the second element equal to ( f k x map).  T let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value p insertLookupWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:xxx|a")]) v insertLookupWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "xxx")]) ^ insertLookupWithKey f 5 "xxx" empty == (Nothing, singleton 5 "xxx") This is how to define  insertLookup using insertLookupWithKey: D let insertLookup kx x t = insertLookupWithKey (\_ a _ -> a) kx x t _ insertLookup 5 "x" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "x")]) i insertLookup 7 "x" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "x")]) O(log n)M. Update a value at a specific key with the result of the provided function.  When the key is not 4 a member of the map, the original map is returned. Y adjust ("new " ++) 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")] U adjust ("new " ++) 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] = adjust ("new " ++) 7 empty == empty O(log n)8. Adjust a value at a specific key. When the key is not 4 a member of the map, the original map is returned. * let f key x = (show key) ++ ":new " ++ x X adjustWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] R adjustWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] : adjustWithKey f 7 empty == empty O(log n). The expression ( f k map) updates the value x  at k (if it is in the map). If (f x) is , the element is  deleted. If it is (4 y ), the key k is bound to the new value y. 6 let f x = if x == "a" then Just "new a" else Nothing O update f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")] K update f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] = update f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" O(log n). The expression ( f k map) updates the  value x at k (if it is in the map). If (f k x) is , # the element is deleted. If it is (4 y ), the key k is bound  to the new value y. G let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing X updateWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] R updateWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] D updateWithKey f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" O(log n). Lookup and update. See also . 7 The function returns changed value, if it is updated. = Returns the original key value if the map entry is deleted. G let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing p updateLookupWithKey f 5 (fromList [(5,"a"), (3,"b")]) == (Just "5:new a", fromList [(3, "b"), (5, "5:new a")]) d updateLookupWithKey f 7 (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a")]) V updateLookupWithKey f 3 (fromList [(5,"a"), (3,"b")]) == (Just "b", singleton 5 "a") O(log n). The expression ( f k map) alters the value x at k, or absence thereof.  7 can be used to insert, delete, or update a value in a 5.  In short : : k ( f k m) = f (: k m).  let f _ = Nothing J alter f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] < alter f 5 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b"   let f _ = Just "c" T alter f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "c")] J alter f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "c")] O(log n). Update the element at index. Calls  when an  invalid index is used. b updateAt (\ _ _ -> Just "x") 0 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "x"), (5, "a")] b updateAt (\ _ _ -> Just "x") 1 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "x")] ^ updateAt (\ _ _ -> Just "x") 2 (fromList [(5,"a"), (3,"b")]) Error: index out of range ^ updateAt (\ _ _ -> Just "x") (-1) (fromList [(5,"a"), (3,"b")]) Error: index out of range T updateAt (\_ _ -> Nothing) 0 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" T updateAt (\_ _ -> Nothing) 1 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" ^ updateAt (\_ _ -> Nothing) 2 (fromList [(5,"a"), (3,"b")]) Error: index out of range ^ updateAt (\_ _ -> Nothing) (-1) (fromList [(5,"a"), (3,"b")]) Error: index out of range O(log n)'. Update the value at the minimal key. d updateMin (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "Xb"), (5, "a")] U updateMin (\ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" O(log n)'. Update the value at the maximal key. d updateMax (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "Xa")] U updateMax (\ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" O(log n)'. Update the value at the minimal key. x updateMinWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"3:b"), (5,"a")] j updateMinWithKey (\ _ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" O(log n)'. Update the value at the maximal key. x updateMaxWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"b"), (5,"5:a")] j updateMaxWithKey (\ _ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" 9The union of a list of maps, with a combining operation:  ( f ==  ( f) B). w unionsWith (++) [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])] 5 == fromList [(3, "bB3"), (5, "aAA3"), (7, "C")] O(n+m)I. Union with a combining function. The implementation uses the efficient  hedge-union algorithm. | unionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "aA"), (7, "C")] O(n+m). H Union with a combining function. The implementation uses the efficient  hedge-union algorithm. Z let f key left_value right_value = (show key) ++ ":" ++ left_value ++ "|" ++ right_value  unionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "5:a|A"), (7, "C")] O(n+m)(. Difference with a combining function.  When two equal keys are M encountered, the combining function is applied to the values of these keys.  If it returns 7, the element is discarded (proper set difference). If  it returns (4 y+), the element is updated with a new value y. & The implementation uses an efficient hedge algorithm comparable with  hedge-union. E let f al ar = if al == "b" then Just (al ++ ":" ++ ar) else Nothing \ differenceWith f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (7, "C")])  == singleton 3 "b:B" O(n+m)@. Difference with a combining function. When two equal keys are L encountered, the combining function is applied to the key and both values.  If it returns 7, the element is discarded (proper set difference). If  it returns (4 y+), the element is updated with a new value y. & The implementation uses an efficient hedge algorithm comparable with  hedge-union. Z let f k al ar = if al == "b" then Just ((show k) ++ ":" ++ al ++ "|" ++ ar) else Nothing ` differenceWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (10, "C")])  == singleton 3 "3:b|B" O(n+m)C. Intersection with a combining function. The implementation uses  an efficient hedge algorithm comparable with  hedge-union. k intersectionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "aA" O(n+m)C. Intersection with a combining function. The implementation uses  an efficient hedge algorithm comparable with  hedge-union. 4 let f k al ar = (show k) ++ ":" ++ al ++ "|" ++ ar n intersectionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "5:a|A" O(n+m)A. A high-performance universal combining function. This function  is used to define , , ,  , ,  and can be 0 used to define other custom combine functions. 6Please make sure you know what is going on when using , B otherwise you can be surprised by unexpected code growth or even # corruption of the data structure. When 5 is given three arguments, it is inlined to the call  site. You should therefore use  only to define your custom 4 combining functions. For example, you could define ,   and  as  R myUnionWithKey f m1 m2 = mergeWithKey (\k x1 x2 -> Just (f k x1 x2)) id id m1 m2 E myDifferenceWithKey f m1 m2 = mergeWithKey f id (const empty) m1 m2 o myIntersectionWithKey f m1 m2 = mergeWithKey (\k x1 x2 -> Just (f k x1 x2)) (const empty) (const empty) m1 m2  When calling  combine only1 only2, a function combining two  IntMaps is created, such that H if a key is present in both maps, it is passed with both corresponding  values to the combine6 function. Depending on the result, the key is either ? present in the result with specified value, or is left out; ? a nonempty subtree present only in the first map is passed to only1 and & the output is added to the result; @ a nonempty subtree present only in the second map is passed to only2 and & the output is added to the result. The only1 and only2 methods Mmust return a map with a subset (possibly empty) of the keys of the given map. A The values can be modified arbitrarily. Most common variants of only1 and  only2 are 7 and 6 B, but for example  f or  q f could be used for any f. O(n). Map values and collect the 4 results. 6 let f x = if x == "a" then Just "new a" else Nothing A mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a" O(n) . Map keys/values and collect the 4 results. D let f k _ = if k < 5 then Just ("key : " ++ (show k)) else Nothing J mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key : 3" O(n). Map values and separate the 9 and : results. / let f a = if a < "c" then Left a else Right a = mapEither f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) C == (fromList [(3,"b"), (5,"a")], fromList [(1,"x"), (7,"z")])  L mapEither (\ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) ? == (empty, fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) O(n) . Map keys/values and separate the 9 and : results. < let f k a = if k < 5 then Left (k * 2) else Right (a ++ a) D mapEitherWithKey f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) A == (fromList [(1,2), (3,6)], fromList [(5,"aa"), (7,"zz")])  T mapEitherWithKey (\_ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) ? == (empty, fromList [(1,"x"), (3,"b"), (5,"a"), (7,"z")]) O(n)-. Map a function over all values in the map. O map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")] O(n)-. Map a function over all values in the map. & let f key x = (show key) ++ ":" ++ x Q mapWithKey f (fromList [(5,"a"), (3,"b")]) == fromList [(3, "3:b"), (5, "5:a")] O(n). The function  threads an accumulating 6 argument through the map in ascending order of keys.  let f a b = (a ++ b, b ++ "X") p mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")]) O(n). The function  threads an accumulating 6 argument through the map in ascending order of keys. < let f a k b = (a ++ " " ++ (show k) ++ "-" ++ b, b ++ "X") { mapAccumWithKey f "Everything:" (fromList [(5,"a"), (3,"b")]) == ("Everything: 3-b 5-a", fromList [(3, "bX"), (5, "aX")]) rO(n). The function r threads an accumulating 6 argument through the map in ascending order of keys. O(n). The function  mapAccumR threads an accumulating 7 argument through the map in descending order of keys.  O(n*log n).   c f s! is the map obtained by applying f to each key of s. )The size of the result may be smaller if f maps two or more distinct G keys to the same new key. In this case the associated values will be  combined using c. c mapKeysWith (++) (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "cdab" c mapKeysWith (++) (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "cdab" O(n)C. Build a map from a set of keys and a function which for each key  computes its value. a fromSet (\k -> replicate k 'a') (Data.Set.fromList [3, 5]) == fromList [(5,"aaaaa"), (3,"aaa")] + fromSet undefined Data.Set.empty == empty  O(n*log n) . Build a map from a list of key/value pairs. See also . K If the list contains more than one value for the same key, the last value  for the key is retained. IIf the keys of the list are ordered, linear-time implementation is used,  with the performance equal to .  fromList [] == empty F fromList [(5,"a"), (3,"b"), (5, "c")] == fromList [(5,"c"), (3,"b")] F fromList [(5,"c"), (3,"b"), (5, "a")] == fromList [(5,"a"), (3,"b")]  O(n*log n) . Build a map from a list of key/0value pairs with a combining function. See also . e fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "ab"), (5, "aba")]  fromListWith (++) [] == empty  O(n*log n) . Build a map from a list of key/0value pairs with a combining function. See also . & let f k a1 a2 = (show k) ++ a1 ++ a2 h fromListWithKey f [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "3ab"), (5, "5a5ba")]  fromListWithKey f [] == empty O(n)5. Build a map from an ascending list in linear time.  :The precondition (input list is ascending) is not checked. J fromAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")] J fromAscList [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "b")] 9 valid (fromAscList [(3,"b"), (5,"a"), (5,"b")]) == True : valid (fromAscList [(5,"a"), (3,"b"), (5,"b")]) == False O(n)^. Build a map from an ascending list in linear time with a combining function for equal keys.  :The precondition (input list is ascending) is not checked. T fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "ba")] B valid (fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")]) == True C valid (fromAscListWith (++) [(5,"a"), (3,"b"), (5,"b")]) == False O(n);. Build a map from an ascending list in linear time with a $ combining function for equal keys.  :The precondition (input list is ascending) is not checked. - let f k a1 a2 = (show k) ++ ":" ++ a1 ++ a2 b fromAscListWithKey f [(3,"b"), (5,"a"), (5,"b"), (5,"b")] == fromList [(3, "b"), (5, "5:b5:ba")] K valid (fromAscListWithKey f [(3,"b"), (5,"a"), (5,"b"), (5,"b")]) == True L valid (fromAscListWithKey f [(5,"a"), (3,"b"), (5,"b"), (5,"b")]) == False O(n)J. Build a map from an ascending list of distinct elements in linear time.   The precondition is not checked. I fromDistinctAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")] A valid (fromDistinctAscList [(3,"b"), (5,"a")]) == True B valid (fromDistinctAscList [(3,"b"), (5,"a"), (5,"b")]) == False ,rj56789:;<>?@ABHOPQSTUVW\]^_`behlmnopqrsz~j56789;<:>?@ABHb`ehz~pqrslmnoPOQSTUVW^_\],rportable provisionallibraries@haskell.orgSafe5  !"#$%&'()*+,-./012345  ()+*,- ./10!"%#$&'234portable provisionallibraries@haskell.org Trustworthy/A set of integers. O(n+m). See . O(1). Is the set empty? O(n). Cardinality of the set.  O(min(n,W))$. Is the value a member of the set?  O(min(n,W))!. Is the element not in the set? O(log n)3. Find largest element smaller than the given one. ) lookupLT 3 (fromList [3, 5]) == Nothing ( lookupLT 5 (fromList [3, 5]) == Just 3 O(log n)4. Find smallest element greater than the given one. ( lookupGT 4 (fromList [3, 5]) == Just 5 ) lookupGT 5 (fromList [3, 5]) == Nothing O(log n):. Find largest element smaller or equal to the given one. ) lookupLE 2 (fromList [3, 5]) == Nothing ( lookupLE 4 (fromList [3, 5]) == Just 3 ( lookupLE 5 (fromList [3, 5]) == Just 5 O(log n);. Find smallest element greater or equal to the given one. ( lookupGE 3 (fromList [3, 5]) == Just 3 ( lookupGE 4 (fromList [3, 5]) == Just 5 ) lookupGE 6 (fromList [3, 5]) == Nothing O(1). The empty set. O(1). A set of one element.  O(min(n,W))>. Add a value to the set. There is no left- or right bias for  IntSets.  O(min(n,W))). Delete a value in the set. Returns the . original set when the value was not present. The union of a list of sets. O(n+m). The union of two sets. O(n+m). Difference between two sets. O(n+m) . The intersection of two sets. O(n+m)9. Is this a proper subset? (ie. a subset but not equal). O(n+m). Is this a subset?  (s1  s2) tells whether s1 is a subset of s2. O(n)3. Filter all elements that satisfy some predicate. O(n)1. partition the set according to some predicate.  O(min(n,W)). The expression ( x set ) is a pair  (set1,set2)  where set1 comprises the elements of set less than x and set2  comprises the elements of set greater than x. ? split 3 (fromList [1..5]) == (fromList [1,2], fromList [4,5])  O(min(n,W)) . Performs a $ but also returns whether the pivot ( element was found in the original set.  O(min(n,W))4. Retrieves the maximal key of the set, and the set  stripped of that element, or  if passed an empty set.  O(min(n,W))4. Retrieves the minimal key of the set, and the set  stripped of that element, or  if passed an empty set.  O(min(n,W))'. Delete and find the minimal element. 2 deleteFindMin set = (findMin set, deleteMin set)  O(min(n,W))'. Delete and find the maximal element. 2 deleteFindMax set = (findMax set, deleteMax set)  O(min(n,W))". The minimal element of the set.  O(min(n,W)) . The maximal element of a set.  O(min(n,W))H. Delete the minimal element. Returns an empty set if the set is empty. =Note that this is a change of behaviour for consistency with    - versions prior to 0.5 threw an error if the  was already empty.  O(min(n,W))H. Delete the maximal element. Returns an empty set if the set is empty. =Note that this is a change of behaviour for consistency with    - versions prior to 0.5 threw an error if the  was already empty.  O(n*min(n,W)).   f s! is the set obtained by applying f to each element of s. It'>s worth noting that the size of the result may be smaller if,  for some (x,y), x /= y && f x == f y O(n)A. Fold the elements in the set using the given right-associative 4 binary operator. This function is an equivalent of  and is present  for compatibility only. CPlease note that fold will be deprecated in the future and removed. O(n)A. Fold the elements in the set using the given right-associative  binary operator, such that  f z ==  f z . .  For example, " toAscList set = foldr (:) [] set O(n). A strict version of &. Each application of the operator is A evaluated before using the result in the next application. This + function is strict in the starting value. O(n)@. Fold the elements in the set using the given left-associative  binary operator, such that  f z ==  f z . .  For example, * toDescList set = foldl (flip (:)) [] set O(n). A strict version of &. Each application of the operator is A evaluated before using the result in the next application. This + function is strict in the starting value. O(n). An alias of ,. The elements of a set in ascending order.  Subject to list fusion. O(n)A. Convert the set to a list of elements. Subject to list fusion. O(n)D. Convert the set to an ascending list of elements. Subject to list  fusion. O(n)D. Convert the set to a descending list of elements. Subject to list  fusion.  O(n*min(n,W))(. Create a set from a list of integers. O(n)2. Build a set from an ascending list of elements.  :The precondition (input list is ascending) is not checked. O(n);. Build a set from an ascending list of distinct elements.  CThe precondition (input list is strictly ascending) is not checked. O(n);. Show the tree that implements the set. The tree is shown " in a compressed, hanging format. O(n). The expression ( hang wide map) shows & the tree that implements the set. If hang is  , a hanging5 tree is shown otherwise a rotated tree is shown. If  wide is ", an extra wide version is shown. vstuvwxyz{|}~7yz{qsutvwx{zy|}~portable provisionallibraries@haskell.orgSafe00portable provisionallibraries@haskell.org TrustworthyfA map of integers to values a.  O(min(n,W)). Find the value at a key.  Calls $ when the element can not be found. B fromList [(5,'a'), (3,'b')] ! 1 Error: element not in the map ( fromList [(5,'a'), (3,'b')] ! 5 == 'a' Same as . O(1). Is the map empty? , Data.IntMap.null (empty) == True - Data.IntMap.null (singleton 1 'a') == False O(n)!. Number of elements in the map. 3 size empty == 0 3 size (singleton 1 'a') == 1 3 size (fromList([(1,'a'), (2,'c'), (3,'b')])) == 3  O(min(n,W))". Is the key a member of the map? 0 member 5 (fromList [(5,'a'), (3,'b')]) == True 1 member 1 (fromList [(5,'a'), (3,'b')]) == False  O(min(n,W))&. Is the key not a member of the map? 4 notMember 5 (fromList [(5,'a'), (3,'b')]) == False 3 notMember 1 (fromList [(5,'a'), (3,'b')]) == True  O(min(n,W))1. Lookup the value at a key in the map. See also  .  O(min(n,W)). The expression ( def k map)  returns the value at key k or returns def when the key is not an  element of the map. < findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x' < findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a' O(log n)=. Find largest key smaller than the given one and return the " corresponding (key, value) pair. 5 lookupLT 3 (fromList [(3,'a'), (5,'b')]) == Nothing ; lookupLT 4 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a') O(log n)>. Find smallest key greater than the given one and return the " corresponding (key, value) pair. ; lookupGT 4 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b') 5 lookupGT 5 (fromList [(3,'a'), (5,'b')]) == Nothing O(log n)@. Find largest key smaller or equal to the given one and return & the corresponding (key, value) pair. 5 lookupLE 2 (fromList [(3,'a'), (5,'b')]) == Nothing ; lookupLE 4 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a') ; lookupLE 5 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b') O(log n)A. Find smallest key greater or equal to the given one and return & the corresponding (key, value) pair. ; lookupGE 3 (fromList [(3,'a'), (5,'b')]) == Just (3, 'a') ; lookupGE 4 (fromList [(3,'a'), (5,'b')]) == Just (5, 'b') 5 lookupGE 6 (fromList [(3,'a'), (5,'b')]) == Nothing O(1). The empty map.  empty == fromList []  size empty == 0 O(1). A map of one element. / singleton 1 'a' == fromList [(1, 'a')]  size (singleton 1 'a') == 1   O(min(n,W)). Insert a new key/value pair in the map. C If the key is already present in the map, the associated value is ( replaced with the supplied value, i.e.   is equivalent to    6. M insert 5 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'x')] W insert 7 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'a'), (7, 'x')] ? insert 5 'x' empty == singleton 5 'x'   O(min(n,W))$. Insert with a combining function.    f key value mp ( will insert the pair (key, value) into mp if key does @ not exist in the map. If the key does exist, the function will  insert f new_value old_value. [ insertWith (++) 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "xxxa")] d insertWith (++) 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] L insertWith (++) 5 "xxx" empty == singleton 5 "xxx"   O(min(n,W))$. Insert with a combining function.    f key value mp ( will insert the pair (key, value) into mp if key does @ not exist in the map. If the key does exist, the function will  insert f key new_value old_value. T let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value ^ insertWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:xxx|a")] d insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] L insertWithKey f 5 "xxx" empty == singleton 5 "xxx"   O(min(n,W)). The expression (  f k x map) 0 is a pair where the first element is equal to ( k map) " and the second element equal to (  f k x map).  T let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value p insertLookupWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:xxx|a")]) v insertLookupWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "xxx")]) ^ insertLookupWithKey f 5 "xxx" empty == (Nothing, singleton 5 "xxx") This is how to define  insertLookup using insertLookupWithKey: D let insertLookup kx x t = insertLookupWithKey (\_ a _ -> a) kx x t _ insertLookup 5 "x" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "x")]) i insertLookup 7 "x" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "x")])   O(min(n,W))?. Delete a key and its value from the map. When the key is not 4 a member of the map, the original map is returned. ; delete 5 (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" I delete 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] 1 delete 5 empty == empty  O(min(n,W))8. Adjust a value at a specific key. When the key is not 4 a member of the map, the original map is returned. Y adjust ("new " ++) 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")] U adjust ("new " ++) 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] = adjust ("new " ++) 7 empty == empty  O(min(n,W))8. Adjust a value at a specific key. When the key is not 4 a member of the map, the original map is returned. * let f key x = (show key) ++ ":new " ++ x X adjustWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] R adjustWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] : adjustWithKey f 7 empty == empty  O(min(n,W)). The expression ( f k map) updates the value x  at k (if it is in the map). If (f x) is , the element is  deleted. If it is (4 y ), the key k is bound to the new value y. 6 let f x = if x == "a" then Just "new a" else Nothing O update f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")] K update f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] = update f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"  O(min(n,W)). The expression ( f k map) updates the value x  at k (if it is in the map). If (f k x) is , the element is  deleted. If it is (4 y ), the key k is bound to the new value y. G let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing X updateWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] R updateWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] D updateWithKey f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a"  O(min(n,W)). Lookup and update. 8 The function returns original value, if it is updated. ! This is different behavior than  . = Returns the original key value if the map entry is deleted. G let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing j updateLookupWithKey f 5 (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:new a")]) d updateLookupWithKey f 7 (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a")]) V updateLookupWithKey f 3 (fromList [(5,"a"), (3,"b")]) == (Just "b", singleton 5 "a")  O(min(n,W)). The expression ( f k map) alters the value x at k, or absence thereof.  8 can be used to insert, delete, or update a value in an .  In short :  k ( f k m) = f ( k m). The union of a list of maps. n unions [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])] 0 == fromList [(3, "b"), (5, "a"), (7, "C")] n unions [(fromList [(5, "A3"), (3, "B3")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "a"), (3, "b")])] 2 == fromList [(3, "B3"), (5, "A3"), (7, "C")] 9The union of a list of maps, with a combining operation. w unionsWith (++) [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])] 5 == fromList [(3, "bB3"), (5, "aAA3"), (7, "C")] O(n+m)'. The (left-biased) union of two maps. ? It prefers the first map when duplicate keys are encountered,  i.e. ( ==  6). r union (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "a"), (7, "C")] O(n+m)'. The union with a combining function. | unionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "aA"), (7, "C")] O(n+m)'. The union with a combining function. Z let f key left_value right_value = (show key) ++ ":" ++ left_value ++ "|" ++ right_value  unionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "5:a|A"), (7, "C")] O(n+m)/. Difference between two maps (based on keys). _ difference (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 3 "b" O(n+m)(. Difference with a combining function. E let f al ar = if al == "b" then Just (al ++ ":" ++ ar) else Nothing \ differenceWith f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (7, "C")])  == singleton 3 "b:B" O(n+m)@. Difference with a combining function. When two equal keys are L encountered, the combining function is applied to the key and both values.  If it returns 4, the element is discarded (proper set difference).  If it returns (4 y+), the element is updated with a new value y. Z let f k al ar = if al == "b" then Just ((show k) ++ ":" ++ al ++ "|" ++ ar) else Nothing ` differenceWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (10, "C")])  == singleton 3 "3:b|B" O(n+m)>. The (left-biased) intersection of two maps (based on keys). a intersection (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "a" O(n+m).. The intersection with a combining function. k intersectionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "aA" O(n+m).. The intersection with a combining function. 4 let f k al ar = (show k) ++ ":" ++ al ++ "|" ++ ar n intersectionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "5:a|A" O(n+m)9. A high-performance universal combining function. Using  =, all combining functions can be defined without any loss of  efficiency (with exception of ,  and , * where sharing of some nodes is lost with ). 6Please make sure you know what is going on when using , B otherwise you can be surprised by unexpected code growth or even # corruption of the data structure. When 5 is given three arguments, it is inlined to the call  site. You should therefore use  only to define your custom 4 combining functions. For example, you could define ,   and  as  R myUnionWithKey f m1 m2 = mergeWithKey (\k x1 x2 -> Just (f k x1 x2)) id id m1 m2 E myDifferenceWithKey f m1 m2 = mergeWithKey f id (const empty) m1 m2 o myIntersectionWithKey f m1 m2 = mergeWithKey (\k x1 x2 -> Just (f k x1 x2)) (const empty) (const empty) m1 m2  When calling  combine only1 only2, a function combining two  s is created, such that H if a key is present in both maps, it is passed with both corresponding  values to the combine6 function. Depending on the result, the key is either ? present in the result with specified value, or is left out; ? a nonempty subtree present only in the first map is passed to only1 and & the output is added to the result; @ a nonempty subtree present only in the second map is passed to only2 and & the output is added to the result. The only1 and only2 methods Mmust return a map with a subset (possibly empty) of the keys of the given map. A The values can be modified arbitrarily. Most common variants of only1 and  only2 are 7 and 6 , but for example 2 f or  < f could be used for any f.   O(min(n,W))'. Update the value at the minimal key. x updateMinWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"3:b"), (5,"a")] j updateMinWithKey (\ _ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" ! O(min(n,W))'. Update the value at the maximal key. x updateMaxWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"b"), (5,"5:a")] j updateMaxWithKey (\ _ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" " O(min(n,W))9. Retrieves the maximal (key,value) pair of the map, and & the map stripped of that element, or  if passed an empty map. Q maxViewWithKey (fromList [(5,"a"), (3,"b")]) == Just ((5,"a"), singleton 3 "b") ! maxViewWithKey empty == Nothing # O(min(n,W))9. Retrieves the minimal (key,value) pair of the map, and & the map stripped of that element, or  if passed an empty map. Q minViewWithKey (fromList [(5,"a"), (3,"b")]) == Just ((3,"b"), singleton 5 "a") ! minViewWithKey empty == Nothing $ O(min(n,W))'. Update the value at the maximal key. d updateMax (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "Xa")] U updateMax (\ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" % O(min(n,W))'. Update the value at the minimal key. d updateMin (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "Xb"), (5, "a")] U updateMin (\ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" & O(min(n,W))4. Retrieves the maximal key of the map, and the map  stripped of that element, or  if passed an empty map. ' O(min(n,W))4. Retrieves the minimal key of the map, and the map  stripped of that element, or  if passed an empty map. ( O(min(n,W))'. Delete and find the maximal element. ) O(min(n,W))'. Delete and find the minimal element. * O(min(n,W)). The minimal key of the map. + O(min(n,W)). The maximal key of the map. , O(min(n,W))D. Delete the minimal key. Returns an empty map if the map is empty. =Note that this is a change of behaviour for consistency with     - versions prior to 0.5 threw an error if the  was already empty. - O(min(n,W))D. Delete the maximal key. Returns an empty map if the map is empty. =Note that this is a change of behaviour for consistency with     - versions prior to 0.5 threw an error if the  was already empty. .O(n+m)9. Is this a proper submap? (ie. a submap but not equal).  Defined as (. = / (==)). /O(n+m)9. Is this a proper submap? (ie. a submap but not equal).  The expression (/ f m1 m2 ) returns  when  m1 and m2 are not equal,  all keys in m1 are in m2 , and when f returns  when @ applied to their respective values. For example, the following  expressions are all :  E isProperSubmapOfBy (==) (fromList [(1,1)]) (fromList [(1,1),(2,2)]) E isProperSubmapOfBy (<=) (fromList [(1,1)]) (fromList [(1,1),(2,2)]) But the following are all 8: K isProperSubmapOfBy (==) (fromList [(1,1),(2,2)]) (fromList [(1,1),(2,2)]) E isProperSubmapOfBy (==) (fromList [(1,1),(2,2)]) (fromList [(1,1)]) K isProperSubmapOfBy (<) (fromList [(1,1)]) (fromList [(1,1),(2,2)]) 0O(n+m). Is this a submap?  Defined as (0 = 1 (==)). 1O(n+m).  The expression (1 f m1 m2 ) returns  if  all keys in m1 are in m2 , and when f returns  when @ applied to their respective values. For example, the following  expressions are all :  ? isSubmapOfBy (==) (fromList [(1,1)]) (fromList [(1,1),(2,2)]) ? isSubmapOfBy (<=) (fromList [(1,1)]) (fromList [(1,1),(2,2)]) E isSubmapOfBy (==) (fromList [(1,1),(2,2)]) (fromList [(1,1),(2,2)]) But the following are all 8: ? isSubmapOfBy (==) (fromList [(1,2)]) (fromList [(1,1),(2,2)]) > isSubmapOfBy (<) (fromList [(1,1)]) (fromList [(1,1),(2,2)]) ? isSubmapOfBy (==) (fromList [(1,1),(2,2)]) (fromList [(1,1)]) 2O(n)-. Map a function over all values in the map. O map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")] 3O(n)-. Map a function over all values in the map. & let f key x = (show key) ++ ":" ++ x Q mapWithKey f (fromList [(5,"a"), (3,"b")]) == fromList [(3, "3:b"), (5, "5:a")] 4O(n).  4 f s == U  $ ; ((k, v) -> (,) k  $ f k v) (R m) ) That is, behaves exactly like a regular ; except that the traversing > function also has access to the key associated with a value.  traverseWithKey (\k v -> if odd k then Just (succ v) else Nothing) (fromList [(1, 'a'), (5, 'e')]) == Just (fromList [(1, 'b'), (5, 'f')]) o traverseWithKey (\k v -> if odd k then Just (succ v) else Nothing) (fromList [(2, 'c')]) == Nothing 5O(n). The function 5 threads an accumulating 6 argument through the map in ascending order of keys.  let f a b = (a ++ b, b ++ "X") p mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")]) 6O(n). The function 6 threads an accumulating 6 argument through the map in ascending order of keys. < let f a k b = (a ++ " " ++ (show k) ++ "-" ++ b, b ++ "X") { mapAccumWithKey f "Everything:" (fromList [(5,"a"), (3,"b")]) == ("Everything: 3-b 5-a", fromList [(3, "bX"), (5, "aX")]) O(n). The function  threads an accumulating 6 argument through the map in ascending order of keys. 7O(n). The function  mapAccumR threads an accumulating 7 argument through the map in descending order of keys. 8 O(n*min(n,W)).  8 f s! is the map obtained by applying f to each key of s. )The size of the result may be smaller if f maps two or more distinct J keys to the same new key. In this case the value at the greatest of the  original keys is retained. e mapKeys (+ 1) (fromList [(5,"a"), (3,"b")]) == fromList [(4, "b"), (6, "a")] W mapKeys (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "c" W mapKeys (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "c" 9 O(n*min(n,W)).  9 c f s! is the map obtained by applying f to each key of s. )The size of the result may be smaller if f maps two or more distinct G keys to the same new key. In this case the associated values will be  combined using c. c mapKeysWith (++) (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "cdab" c mapKeysWith (++) (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "cdab" : O(n*min(n,W)).  : f s == 8 f s, but works only when f  is strictly monotonic.  That is, for any values x and y, if x < y then f x < f y.   The precondition is not checked.  Semi-formally, we have:  . and [x < y ==> f x < f y | x <- ls, y <- ls] = ==> mapKeysMonotonic f s == mapKeys f s  where ls = keys s This means that f9 maps distinct original keys to distinct resulting keys. 4 This function has slightly better performance than 8. a mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")]) == fromList [(6, "b"), (10, "a")] ;O(n)1. Filter all values that satisfy some predicate. A filter (> "a") (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" 7 filter (> "x") (fromList [(5,"a"), (3,"b")]) == empty 7 filter (< "a") (fromList [(5,"a"), (3,"b")]) == empty <O(n). Filter all keys/$values that satisfy some predicate. P filterWithKey (\k _ -> k > 4) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" =O(n);. Partition the map according to some predicate. The first F map contains all elements that satisfy the predicate, the second all , elements that fail the predicate. See also C. W partition (> "a") (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", singleton 5 "a") [ partition (< "x") (fromList [(5,"a"), (3,"b")]) == (fromList [(3, "b"), (5, "a")], empty) [ partition (> "x") (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3, "b"), (5, "a")]) >O(n);. Partition the map according to some predicate. The first F map contains all elements that satisfy the predicate, the second all , elements that fail the predicate. See also C. g partitionWithKey (\ k _ -> k > 3) (fromList [(5,"a"), (3,"b")]) == (singleton 5 "a", singleton 3 "b") k partitionWithKey (\ k _ -> k < 7) (fromList [(5,"a"), (3,"b")]) == (fromList [(3, "b"), (5, "a")], empty) k partitionWithKey (\ k _ -> k > 7) (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3, "b"), (5, "a")]) ?O(n). Map values and collect the 4 results. 6 let f x = if x == "a" then Just "new a" else Nothing A mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a" @O(n) . Map keys/values and collect the 4 results. D let f k _ = if k < 5 then Just ("key : " ++ (show k)) else Nothing J mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key : 3" AO(n). Map values and separate the 9 and : results. / let f a = if a < "c" then Left a else Right a = mapEither f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) C == (fromList [(3,"b"), (5,"a")], fromList [(1,"x"), (7,"z")])  L mapEither (\ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) ? == (empty, fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) BO(n) . Map keys/values and separate the 9 and : results. < let f k a = if k < 5 then Left (k * 2) else Right (a ++ a) D mapEitherWithKey f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) A == (fromList [(1,2), (3,6)], fromList [(5,"aa"), (7,"zz")])  T mapEitherWithKey (\_ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) ? == (empty, fromList [(1,"x"), (3,"b"), (5,"a"), (7,"z")]) C O(min(n,W)). The expression (C k map ) is a pair  (map1,map2)  where all keys in map1 are lower than k and all keys in  map2 larger than k. Any key equal to k is found in neither map1 nor map2. O split 2 (fromList [(5,"a"), (3,"b")]) == (empty, fromList [(3,"b"), (5,"a")]) C split 3 (fromList [(5,"a"), (3,"b")]) == (empty, singleton 5 "a") M split 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", singleton 5 "a") C split 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", empty) O split 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], empty) D O(min(n,W)) . Performs a C$ but also returns whether the pivot $ key was found in the original map. ^ splitLookup 2 (fromList [(5,"a"), (3,"b")]) == (empty, Nothing, fromList [(3,"b"), (5,"a")]) S splitLookup 3 (fromList [(5,"a"), (3,"b")]) == (empty, Just "b", singleton 5 "a") \ splitLookup 4 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Nothing, singleton 5 "a") S splitLookup 5 (fromList [(5,"a"), (3,"b")]) == (singleton 3 "b", Just "a", empty) ^ splitLookup 6 (fromList [(5,"a"), (3,"b")]) == (fromList [(3,"b"), (5,"a")], Nothing, empty) EO(n)?. Fold the values in the map using the given right-associative  binary operator, such that E f z ==  f z . M.  For example,   elems map = foldr (:) [] map  let f a len = len + (length a) 0 foldr f 0 (fromList [(5,"a"), (3,"bbb")]) == 4 FO(n). A strict version of E&. Each application of the operator is A evaluated before using the result in the next application. This + function is strict in the starting value. GO(n)>. Fold the values in the map using the given left-associative  binary operator, such that G f z ==  f z . M.  For example,  ' elems = reverse . foldl (flip (:)) []  let f len a = len + (length a) 0 foldl f 0 (fromList [(5,"a"), (3,"bbb")]) == 4 HO(n). A strict version of G&. Each application of the operator is A evaluated before using the result in the next application. This + function is strict in the starting value. IO(n)H. Fold the keys and values in the map using the given right-associative  binary operator, such that  I f z ==  (= f) z . S.  For example,  2 keys map = foldrWithKey (\k x ks -> k:ks) [] map A let f k a result = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")" K foldrWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (5:a)(3:b)" JO(n). A strict version of I&. Each application of the operator is A evaluated before using the result in the next application. This + function is strict in the starting value. KO(n)G. Fold the keys and values in the map using the given left-associative  binary operator, such that  K f z ==  (\z' (kx, x) -> f z' kx x) z . S.  For example,  4 keys = reverse . foldlWithKey (\ks k x -> k:ks) [] A let f result k a = result ++ "(" ++ (show k) ++ ":" ++ a ++ ")" K foldlWithKey f "Map: " (fromList [(5,"a"), (3,"b")]) == "Map: (3:b)(5:a)" LO(n). A strict version of K&. Each application of the operator is A evaluated before using the result in the next application. This + function is strict in the starting value. MO(n). F Return all elements of the map in the ascending order of their keys.  Subject to list fusion. 2 elems (fromList [(5,"a"), (3,"b")]) == ["b","a"]  elems empty == [] NO(n)A. Return all keys of the map in ascending order. Subject to list  fusion. - keys (fromList [(5,"a"), (3,"b")]) == [3,5]  keys empty == [] OO(n). An alias for S. Returns all key/value pairs in the 5 map in ascending key order. Subject to list fusion. < assocs (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]  assocs empty == [] P O(n*min(n,W))". The set of all keys of the map. E keysSet (fromList [(5,"a"), (3,"b")]) == Data.IntSet.fromList [3,5] $ keysSet empty == Data.IntSet.empty QO(n)C. Build a map from a set of keys and a function which for each key  computes its value. d fromSet (\k -> replicate k 'a') (Data.IntSet.fromList [3, 5]) == fromList [(5,"aaaaa"), (3,"aaa")] . fromSet undefined Data.IntSet.empty == empty RO(n)". Convert the map to a list of key/value pairs. Subject to list  fusion. < toList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")]  toList empty == [] SO(n)". Convert the map to a list of key/value pairs where the 6 keys are in ascending order. Subject to list fusion. ? toAscList (fromList [(5,"a"), (3,"b")]) == [(3,"b"), (5,"a")] TO(n)". Convert the map to a list of key/value pairs where the keys 2 are in descending order. Subject to list fusion. @ toDescList (fromList [(5,"a"), (3,"b")]) == [(5,"a"), (3,"b")] U O(n*min(n,W))!. Create a map from a list of key/ value pairs.  fromList [] == empty F fromList [(5,"a"), (3,"b"), (5, "c")] == fromList [(5,"c"), (3,"b")] F fromList [(5,"c"), (3,"b"), (5, "a")] == fromList [(5,"a"), (3,"b")] V O(n*min(n,W))!. Create a map from a list of key/0value pairs with a combining function. See also Y. e fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"c")] == fromList [(3, "ab"), (5, "cba")]  fromListWith (++) [] == empty W O(n*min(n,W)) . Build a map from a list of key/Bvalue pairs with a combining function. See also fromAscListWithKey'. T let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value n fromListWithKey f [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"c")] == fromList [(3, "3:a|b"), (5, "5:c|5:b|a")]  fromListWithKey f [] == empty XO(n) . Build a map from a list of key/value pairs where " the keys are in ascending order. J fromAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")] J fromAscList [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "b")] YO(n) . Build a map from a list of key/value pairs where K the keys are in ascending order, with a combining function on equal keys.  :The precondition (input list is ascending) is not checked. T fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "ba")] ZO(n) . Build a map from a list of key/value pairs where K the keys are in ascending order, with a combining function on equal keys.  :The precondition (input list is ascending) is not checked. T let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value W fromAscListWithKey f [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "5:b|a")] [O(n) . Build a map from a list of key/value pairs where 3 the keys are in ascending order and all distinct.  CThe precondition (input list is strictly ascending) is not checked. I fromDistinctAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")] 1Return a word where only the highest bit is set. \O(n);. Show the tree that implements the map. The tree is shown " in a compressed, hanging format. ]O(n). The expression (] hang wide map) shows & the tree that implements the map. If hang is  , a hanging5 tree is shown otherwise a rotated tree is shown. If  wide is ", an extra wide version is shown.       !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]{      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]portable provisionallibraries@haskell.org Trustworthy+^ O(min(n,W)). The expression (^ def k map)  returns the value at key k or returns def when the key is not an  element of the map. < findWithDefault 'x' 1 (fromList [(5,'a'), (3,'b')]) == 'x' < findWithDefault 'x' 5 (fromList [(5,'a'), (3,'b')]) == 'a' _O(1). A map of one element. / singleton 1 'a' == fromList [(1, 'a')]  size (singleton 1 'a') == 1 ` O(min(n,W)). Insert a new key/value pair in the map. C If the key is already present in the map, the associated value is ( replaced with the supplied value, i.e. ` is equivalent to  a 6. M insert 5 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'x')] W insert 7 'x' (fromList [(5,'a'), (3,'b')]) == fromList [(3, 'b'), (5, 'a'), (7, 'x')] ? insert 5 'x' empty == singleton 5 'x' a O(min(n,W))$. Insert with a combining function.  a f key value mp ( will insert the pair (key, value) into mp if key does @ not exist in the map. If the key does exist, the function will  insert f new_value old_value. [ insertWith (++) 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "xxxa")] d insertWith (++) 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] L insertWith (++) 5 "xxx" empty == singleton 5 "xxx" b O(min(n,W))$. Insert with a combining function.  b f key value mp ( will insert the pair (key, value) into mp if key does @ not exist in the map. If the key does exist, the function will  insert f key new_value old_value.  T let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value ^ insertWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:xxx|a")] d insertWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "xxx")] L insertWithKey f 5 "xxx" empty == singleton 5 "xxx" 7If the key exists in the map, this function is lazy in x but strict  in the result of f. c O(min(n,W)). The expression (c f k x map) 0 is a pair where the first element is equal to ( k map) " and the second element equal to (b f k x map).  T let f key new_value old_value = (show key) ++ ":" ++ new_value ++ "|" ++ old_value p insertLookupWithKey f 5 "xxx" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:xxx|a")]) v insertLookupWithKey f 7 "xxx" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "xxx")]) ^ insertLookupWithKey f 5 "xxx" empty == (Nothing, singleton 5 "xxx") This is how to define  insertLookup using insertLookupWithKey: D let insertLookup kx x t = insertLookupWithKey (\_ a _ -> a) kx x t _ insertLookup 5 "x" (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "x")]) i insertLookup 7 "x" (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a"), (7, "x")]) d O(min(n,W))8. Adjust a value at a specific key. When the key is not 4 a member of the map, the original map is returned. Y adjust ("new " ++) 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")] U adjust ("new " ++) 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] = adjust ("new " ++) 7 empty == empty e O(min(n,W))8. Adjust a value at a specific key. When the key is not 4 a member of the map, the original map is returned. * let f key x = (show key) ++ ":new " ++ x X adjustWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] R adjustWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] : adjustWithKey f 7 empty == empty f O(min(n,W)). The expression (f f k map) updates the value x  at k (if it is in the map). If (f x) is , the element is  deleted. If it is (4 y ), the key k is bound to the new value y. 6 let f x = if x == "a" then Just "new a" else Nothing O update f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "new a")] K update f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] = update f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" g O(min(n,W)). The expression (f f k map) updates the value x  at k (if it is in the map). If (f k x) is , the element is  deleted. If it is (4 y ), the key k is bound to the new value y. G let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing X updateWithKey f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "5:new a")] R updateWithKey f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a")] D updateWithKey f 3 (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" h O(min(n,W)). Lookup and update. 8 The function returns original value, if it is updated. ! This is different behavior than  . = Returns the original key value if the map entry is deleted. G let f k x = if x == "a" then Just ((show k) ++ ":new a") else Nothing j updateLookupWithKey f 5 (fromList [(5,"a"), (3,"b")]) == (Just "a", fromList [(3, "b"), (5, "5:new a")]) d updateLookupWithKey f 7 (fromList [(5,"a"), (3,"b")]) == (Nothing, fromList [(3, "b"), (5, "a")]) V updateLookupWithKey f 3 (fromList [(5,"a"), (3,"b")]) == (Just "b", singleton 5 "a") iO(log n). The expression (i f k map) alters the value x at k, or absence thereof.  i8 can be used to insert, delete, or update a value in an .  In short :  k (i f k m) = f ( k m). j9The union of a list of maps, with a combining operation. w unionsWith (++) [(fromList [(5, "a"), (3, "b")]), (fromList [(5, "A"), (7, "C")]), (fromList [(5, "A3"), (3, "B3")])] 5 == fromList [(3, "bB3"), (5, "aAA3"), (7, "C")] kO(n+m)'. The union with a combining function. | unionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "aA"), (7, "C")] lO(n+m)'. The union with a combining function. Z let f key left_value right_value = (show key) ++ ":" ++ left_value ++ "|" ++ right_value  unionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == fromList [(3, "b"), (5, "5:a|A"), (7, "C")] mO(n+m)(. Difference with a combining function. E let f al ar = if al == "b" then Just (al ++ ":" ++ ar) else Nothing \ differenceWith f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (7, "C")])  == singleton 3 "b:B" nO(n+m)@. Difference with a combining function. When two equal keys are L encountered, the combining function is applied to the key and both values.  If it returns 4, the element is discarded (proper set difference).  If it returns (4 y+), the element is updated with a new value y. Z let f k al ar = if al == "b" then Just ((show k) ++ ":" ++ al ++ "|" ++ ar) else Nothing ` differenceWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (3, "B"), (10, "C")])  == singleton 3 "3:b|B" oO(n+m).. The intersection with a combining function. k intersectionWith (++) (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "aA" pO(n+m).. The intersection with a combining function. 4 let f k al ar = (show k) ++ ":" ++ al ++ "|" ++ ar n intersectionWithKey f (fromList [(5, "a"), (3, "b")]) (fromList [(5, "A"), (7, "C")]) == singleton 5 "5:a|A" qO(n+m)9. A high-performance universal combining function. Using  q=, all combining functions can be defined without any loss of  efficiency (with exception of ,  and , * where sharing of some nodes is lost with q). 6Please make sure you know what is going on when using q, B otherwise you can be surprised by unexpected code growth or even # corruption of the data structure. When q5 is given three arguments, it is inlined to the call  site. You should therefore use q only to define your custom 4 combining functions. For example, you could define l,  n and p as  R myUnionWithKey f m1 m2 = mergeWithKey (\k x1 x2 -> Just (f k x1 x2)) id id m1 m2 E myDifferenceWithKey f m1 m2 = mergeWithKey f id (const empty) m1 m2 o myIntersectionWithKey f m1 m2 = mergeWithKey (\k x1 x2 -> Just (f k x1 x2)) (const empty) (const empty) m1 m2  When calling q combine only1 only2, a function combining two  s is created, such that H if a key is present in both maps, it is passed with both corresponding  values to the combine6 function. Depending on the result, the key is either ? present in the result with specified value, or is left out; ? a nonempty subtree present only in the first map is passed to only1 and & the output is added to the result; @ a nonempty subtree present only in the second map is passed to only2 and & the output is added to the result. The only1 and only2 methods Mmust return a map with a subset (possibly empty) of the keys of the given map. B The values can be modified arbitrarily. Most common variants of only1 and  only2 are 7 and 6 , but for example v f or  < f could be used for any f. rO(log n)'. Update the value at the minimal key. x updateMinWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"3:b"), (5,"a")] j updateMinWithKey (\ _ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" sO(log n)'. Update the value at the maximal key. x updateMaxWithKey (\ k a -> Just ((show k) ++ ":" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3,"b"), (5,"5:a")] j updateMaxWithKey (\ _ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" tO(log n)'. Update the value at the maximal key. d updateMax (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "Xa")] U updateMax (\ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 3 "b" uO(log n)'. Update the value at the minimal key. d updateMin (\ a -> Just ("X" ++ a)) (fromList [(5,"a"), (3,"b")]) == fromList [(3, "Xb"), (5, "a")] U updateMin (\ _ -> Nothing) (fromList [(5,"a"), (3,"b")]) == singleton 5 "a" vO(n)-. Map a function over all values in the map. O map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")] wO(n)-. Map a function over all values in the map. & let f key x = (show key) ++ ":" ++ x Q mapWithKey f (fromList [(5,"a"), (3,"b")]) == fromList [(3, "3:b"), (5, "5:a")] xO(n). The function x threads an accumulating 6 argument through the map in ascending order of keys.  let f a b = (a ++ b, b ++ "X") p mapAccum f "Everything: " (fromList [(5,"a"), (3,"b")]) == ("Everything: ba", fromList [(3, "bX"), (5, "aX")]) yO(n). The function y threads an accumulating 6 argument through the map in ascending order of keys. < let f a k b = (a ++ " " ++ (show k) ++ "-" ++ b, b ++ "X") { mapAccumWithKey f "Everything:" (fromList [(5,"a"), (3,"b")]) == ("Everything: 3-b 5-a", fromList [(3, "bX"), (5, "aX")]) O(n). The function  threads an accumulating A argument through the map in ascending order of keys. Strict in 8 the accumulating argument and the both elements of the  result of the function. zO(n). The function  mapAccumR threads an accumulating 7 argument through the map in descending order of keys. { O(n*log n).  { c f s! is the map obtained by applying f to each key of s. )The size of the result may be smaller if f maps two or more distinct G keys to the same new key. In this case the associated values will be  combined using c. c mapKeysWith (++) (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 1 "cdab" c mapKeysWith (++) (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")]) == singleton 3 "cdab" |O(n). Map values and collect the 4 results. 6 let f x = if x == "a" then Just "new a" else Nothing A mapMaybe f (fromList [(5,"a"), (3,"b")]) == singleton 5 "new a" }O(n) . Map keys/values and collect the 4 results. D let f k _ = if k < 5 then Just ("key : " ++ (show k)) else Nothing J mapMaybeWithKey f (fromList [(5,"a"), (3,"b")]) == singleton 3 "key : 3" ~O(n). Map values and separate the 9 and : results. / let f a = if a < "c" then Left a else Right a = mapEither f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) C == (fromList [(3,"b"), (5,"a")], fromList [(1,"x"), (7,"z")])  L mapEither (\ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) ? == (empty, fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) O(n) . Map keys/values and separate the 9 and : results. < let f k a = if k < 5 then Left (k * 2) else Right (a ++ a) D mapEitherWithKey f (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) A == (fromList [(1,2), (3,6)], fromList [(5,"aa"), (7,"zz")])  T mapEitherWithKey (\_ a -> Right a) (fromList [(5,"a"), (3,"b"), (1,"x"), (7,"z")]) ? == (empty, fromList [(1,"x"), (3,"b"), (5,"a"), (7,"z")]) O(n)C. Build a map from a set of keys and a function which for each key  computes its value. d fromSet (\k -> replicate k 'a') (Data.IntSet.fromList [3, 5]) == fromList [(5,"aaaaa"), (3,"aaa")] . fromSet undefined Data.IntSet.empty == empty  O(n*min(n,W))!. Create a map from a list of key/ value pairs.  fromList [] == empty F fromList [(5,"a"), (3,"b"), (5, "c")] == fromList [(5,"c"), (3,"b")] F fromList [(5,"c"), (3,"b"), (5, "a")] == fromList [(5,"a"), (3,"b")]  O(n*min(n,W))!. Create a map from a list of key/0value pairs with a combining function. See also . e fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "ab"), (5, "aba")]  fromListWith (++) [] == empty  O(n*min(n,W)) . Build a map from a list of key/Bvalue pairs with a combining function. See also fromAscListWithKey'. e fromListWith (++) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"a")] == fromList [(3, "ab"), (5, "aba")]  fromListWith (++) [] == empty O(n) . Build a map from a list of key/value pairs where " the keys are in ascending order. J fromAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")] J fromAscList [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "b")] O(n) . Build a map from a list of key/value pairs where K the keys are in ascending order, with a combining function on equal keys.  :The precondition (input list is ascending) is not checked. T fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "ba")] O(n) . Build a map from a list of key/value pairs where K the keys are in ascending order, with a combining function on equal keys.  :The precondition (input list is ascending) is not checked. T fromAscListWith (++) [(3,"b"), (5,"a"), (5,"b")] == fromList [(3, "b"), (5, "ba")] O(n) . Build a map from a list of key/value pairs where 3 the keys are in ascending order and all distinct.  CThe precondition (input list is strictly ascending) is not checked. I fromDistinctAscList [(3,"b"), (5,"a")] == fromList [(3, "b"), (5, "a")] .^_`abcdefghijklmnopqrstuvwxyz{|}~e "#&'()*+,-./0148:;<=>CDEFGHIJKLMNOPRST\]^_`abcdefghijklmnopqrstuvwxyz{|}~e^_`abc defghikljmnopqvw4xyz8{:EGIKFHJLMNOPRST;<=>|}~CD01./*+,-)(utrs'&#"\],^_`abcdefghijklmnopqrstuvwxyz{|}~portable provisionallibraries@haskell.org Trustworthye      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]e     23456789:EGIKFHJLMNOPQRUVWSTXYZ[;<=>?@ABCD01./*+,-)(%$ !'&#"\]portable provisionallibraries@haskell.org Trustworthy Deprecated. As of version 0.5, replaced by  . O(log n) . Same as  +, but the result of the combining function A is evaluated to WHNF before inserted to the map. In contrast to  ., the value argument is not evaluted when not # needed by the combining function.  Deprecated. As of version 0.5, replaced by  . O(log n) . Same as  ", but the result of the combining J function is evaluated to WHNF before inserted to the map. In contrast to  *, the value argument is not evaluted when ' not needed by the combining function.  Deprecated. As of version 0.5, replaced by E. O(n)-. Fold the values in the map using the given C right-associative binary operator. This function is an equivalent  of E( and is present for compatibility only.  Deprecated. As of version 0.5, replaced by I. O(n)6. Fold the keys and values in the map using the given C right-associative binary operator. This function is an equivalent  of I( and is present for compatibility only. i      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]portable experimentallibraries@haskell.org TrustworthyNA  is a simple pairing heap. %View of the right end of a sequence. *the sequence minus the rightmost element,  and the rightmost element empty sequence $View of the left end of a sequence. .leftmost element and the rest of the sequence empty sequence ;This is essentially a clone of Control.Monad.State.Strict. "General-purpose finite sequences. EGiven the size of a digit and the digit itself, efficiently converts  it to a FingerTree. 0A helper method: a strict version of mapAccumL. 0 takes an Applicative-wrapped construction of a D piece of a FingerTree, assumed to always have the same size (which D is put in the second argument), and replicates it as many times as ) specified. This is a generalization of , which itself 4 is a generalization of many Data.Sequence methods. O(1). The empty sequence. O(1). A singleton sequence. O(log n).  replicate n x is a sequence consisting of n copies of x.  is an  version of  , and makes  O(log n) calls to  and . , replicateA n x = sequenceA (replicate n x)  is a sequence counterpart of . + replicateM n x = sequence (replicate n x) O(1)0. Add an element to the left end of a sequence. A Mnemonic: a triangle with the single element at the pointy end. O(1)1. Add an element to the right end of a sequence. A Mnemonic: a triangle with the single element at the pointy end. O(log(min(n1,n2))). Concatenate two sequences. ?Builds a sequence from a seed value. Takes time linear in the  number of generated elements. WARNING: If the number of generated 7 elements is infinite, this method will not terminate.  f x is equivalent to  ( ( swap . f) x). O(n)?. Constructs a sequence by repeated application of a function  to a seed value. B iterateN n f x = fromList (Prelude.take n (Prelude.iterate f x)) O(1). Is this the empty sequence? O(1)*. The number of elements in the sequence. O(1)&. Analyse the left end of a sequence. O(1)'. Analyse the right end of a sequence.  is similar to $, but returns a sequence of reduced  values from the left: U scanl f z (fromList [x1, x2, ...]) = fromList [z, z `f` x1, (z `f` x1) `f` x2, ...]  is a variant of & that has no starting value argument: C scanl1 f (fromList [x1, x2, ...]) = fromList [x1, x1 `f` x2, ...]  is the right-to-left dual of .  is a variant of & that has no starting value argument. O(log(min(i,n-i)))). The element at the specified position, > counting from 0. The argument should thus be a non-negative - integer less than the size of the sequence. " If the position is out of range,  fails with an error. O(log(min(i,n-i)))1. Replace the element at the specified position. E If the position is out of range, the original sequence is returned. O(log(min(i,n-i)))0. Update the element at the specified position. E If the position is out of range, the original sequence is returned. A generalization of ,  takes a mapping function ! that also depends on the element'!s index, and applies it to every  element in the sequence. O(log(min(i,n-i))) . The first i elements of a sequence.  If i is negative,  i s yields the empty sequence. % If the sequence contains fewer than i elements, the whole sequence  is returned. O(log(min(i,n-i)))). Elements of a sequence after the first i.  If i is negative,  i s yields the whole sequence. % If the sequence contains fewer than i elements, the empty sequence  is returned. O(log(min(i,n-i)))(. Split a sequence at a given position.   i s = ( i s,  i s). O(n)8. Returns a sequence of all suffixes of this sequence,  longest first. For example,  ^ tails (fromList "abc") = fromList [fromList "abc", fromList "bc", fromList "c", fromList ""] Evaluating the ith suffix takes O(log(min(i, n-i))), but evaluating $ every suffix in the sequence takes O(n) due to sharing. O(n)8. Returns a sequence of all prefixes of this sequence,  shortest first. For example,  ^ inits (fromList "abc") = fromList [fromList "", fromList "a", fromList "ab", fromList "abc"] Evaluating the ith prefix takes O(log(min(i, n-i))), but evaluating $ every prefix in the sequence takes O(n) due to sharing. DGiven a function to apply to tails of a tree, applies that function & to every tail of the specified tree. DGiven a function to apply to inits of a tree, applies that function & to every init of the specified tree.  is a version of  that also provides access  to the index of each element.  is a version of  that also provides access  to the index of each element. O(i) where i is the prefix length.  , applied  to a predicate p and a sequence xs, returns the longest prefix  (possibly empty) of xs of elements that satisfy p. O(i) where i is the suffix length.  , applied  to a predicate p and a sequence xs, returns the longest suffix  (possibly empty) of xs of elements that satisfy p.  p xs is equivalent to  ( p ( xs)). O(i) where i is the prefix length.  p xs returns  the suffix remaining after  p xs. O(i) where i is the suffix length.  p xs returns  the prefix remaining after  p xs.  p xs is equivalent to  ( p ( xs)). O(i) where i is the prefix length.  , applied to  a predicate p and a sequence xs, returns a pair whose first 3 element is the longest prefix (possibly empty) of xs of elements that  satisfy p: and the second element is the remainder of the sequence. O(i) where i is the suffix length. , applied to a  predicate p and a sequence xs, returns a pair whose first element  is the longest suffix (possibly empty) of xs of elements that  satisfy p: and the second element is the remainder of the sequence. O(i) where i is the breakpoint index. , applied to a  predicate p and a sequence xs%, returns a pair whose first element + is the longest prefix (possibly empty) of xs of elements that  do not satisfy p, and the second element is the remainder of  the sequence.  p is equivalent to  (not . p).  p is equivalent to  (not . p). O(n). The  function takes a predicate p and a  sequence xs6 and returns sequences of those elements which do and  do not satisfy the predicate. O(n). The  function takes a predicate p and a sequence  xs< and returns a sequence of those elements which satisfy the  predicate. 4 finds the leftmost index of the specified element, ! if it is present, and otherwise . 5 finds the rightmost index of the specified element, ! if it is present, and otherwise . 2 finds the indices of the specified element, from * left to right (i.e. in ascending order). 2 finds the indices of the specified element, from + right to left (i.e. in descending order).  p xs. finds the index of the leftmost element that  satisfies p, if any exist.  p xs/ finds the index of the rightmost element that  satisfies p, if any exist.  p, finds all indices of elements that satisfy p,  in ascending order.  p, finds all indices of elements that satisfy p,  in descending order. O(n)4. Create a sequence from a finite list of elements.  There is a function # in the opposite direction for all  instances of the  class, including . O(n). The reverse of a sequence.  O(min(n1,n2)). , takes two sequences and returns a sequence E of corresponding pairs. If one input is short, excess elements are 6 discarded from the right end of the longer sequence.  O(min(n1,n2)).  generalizes  by zipping with the F function given as the first argument, instead of a tupling function.  For example,  zipWith (+)) is applied to two sequences to take the ! sequence of corresponding sums. O(min(n1,n2,n3)). % takes three sequences and returns a # sequence of triples, analogous to . O(min(n1,n2,n3)). ! takes a function which combines F three elements, as well as three sequences and returns a sequence of - their point-wise combinations, analogous to . O(min(n1,n2,n3,n4)). $ takes four sequences and returns a & sequence of quadruples, analogous to . O(min(n1,n2,n3,n4)). ! takes a function which combines D four elements, as well as four sequences and returns a sequence of - their point-wise combinations, analogous to .  O(n log n).  sorts the specified  by the natural 0 ordering of its elements. The sort is stable.  If stability is not required,  can be considerably - faster, and in particular uses less memory.  O(n log n).  sorts the specified  according to the , specified comparator. The sort is stable.  If stability is not required,  can be considerably - faster, and in particular uses less memory.  O(n log n).  sorts the specified  by C the natural ordering of its elements, but the sort is not stable. ? This algorithm is frequently faster and uses less memory than , < and performs extremely well -- frequently twice as fast as  -- - when the sequence is already nearly sorted.  O(n log n). A generalization of ,  A takes an arbitrary comparator and sorts the specified sequence. B The sort is not stable. This algorithm is frequently faster and  uses less memory than !, and performs extremely well --  frequently twice as fast as ! -- when the sequence is already  nearly sorted. @fromList2, given a list and its length, constructs a completely E balanced Seq whose elements are that list using the applicativeTree  generalization. ), given a comparator function, unrolls a  into  a sorted list. =, given an ordering function and a mechanism for queueifying  elements, converts a  to a .  merges two s.       !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~CC     "! %$#&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ portable experimentallibraries@haskell.orgSafe Multi-way trees, also known as  rose trees.  label value zero or more child trees &Neat 2-dimensional drawing of a tree. (Neat 2-dimensional drawing of a forest. %The elements of a tree in pre-order. *Lists of nodes at each level of the tree. Build a tree from a seed value *Build a forest from a list of seed values +Monadic tree builder, in depth-first order -Monadic forest builder, in depth-first order .Monadic tree builder, in breadth-first order, ! using an algorithm adapted from  JBreadth-First Numbering: Lessons from a Small Exercise in Algorithm Design,  by Chris Okasaki, ICFP'00. 0Monadic forest builder, in breadth-first order, ! using an algorithm adapted from  JBreadth-First Numbering: Lessons from a Small Exercise in Algorithm Design,  by Chris Okasaki, ICFP'00.  portable experimentallibraries@haskell.org Trustworthy-An edge from the first vertex to the second. The bounds of a . EAdjacency list representation of a graph, mapping each vertex to its  list of successors. /Table indexed by a contiguous set of vertices. %Abstract representation of vertices. Strongly connected component. A maximal set of mutually  reachable vertices. A single vertex that is not  in any cycle. 9The vertices of a list of strongly connected components. 0The vertices of a strongly connected component. EThe strongly connected components of a directed graph, topologically  sorted. EThe strongly connected components of a directed graph, topologically & sorted. The function is the same as , except that / all the information about each node retained. 1 This interface is used when you expect to apply  to  (some of) the result of  , so you don't want to lose the  dependency information. All vertices of a graph. All edges of a graph. $Build a graph from a list of edges. +The graph obtained by reversing all edges. .A table of the count of edges from each node. .A table of the count of edges into each node.  Identical to , except that the return value B does not include the function which maps keys to vertices. This  version of ! is for backwards compatibility. @Build a graph from a list of nodes uniquely identified by keys, > with a list of keys of nodes this node should have edges to. ' The out-list may contain keys that don't correspond to ' nodes of the graph; they are ignored. FA spanning forest of the graph, obtained from a depth-first search of > the graph starting from each vertex in an unspecified order. EA spanning forest of the part of the graph reachable from the listed G vertices, obtained from a depth-first search of the graph starting at ' each of the listed vertices in order. !A topological sort of the graph. A The order is partially specified by the condition that a vertex i  precedes j whenever j is reachable from i but not vice versa. %The connected components of a graph. H Two vertices are connected if there is a path between them, traversing  edges in either direction. .The strongly connected components of a graph. 2A list of vertices reachable from a given vertex. /Is the second vertex reachable from the first? 'The biconnected components of a graph. B An undirected graph is biconnected if the deletion of any vertex  leaves it connected. 58The graph: a list of nodes uniquely identified by keys, 6 with a list of keys of nodes this node has edges to. ' The out-list may contain keys that don't correspond to - nodes of the graph; such edges are ignored. 8The graph: a list of nodes uniquely identified by keys, 6 with a list of keys of nodes this node has edges to. ' The out-list may contain keys that don't correspond to - nodes of the graph; such edges are ignored. Topologically sorted 1 portable provisionallibraries@haskell.orgSafe Deprecated. As of version 0.5, replaced by . O(log n) . Same as E-, but the value being inserted to the map is . evaluated to WHNF beforehand. In contrast to , 5 the value argument is not evaluted when not needed. "For example, to update a counter:  insertWith' (+) k 1 m  Deprecated. As of version 0.5, replaced by  . O(log n) . Same as F-, but the value being inserted to the map is . evaluated to WHNF beforehand. In contrast to , 5 the value argument is not evaluted when not needed.  Deprecated. As of version 0.5, replaced by  . O(log n) . Same as G", but the value being inserted to 9 the map is evaluated to WHNF beforehand. In contrast to  %, the value argument is not evaluted  when not needed.  Deprecated. As of version 0.5, replaced by . O(n)?. Fold the values in the map using the given right-associative 4 binary operator. This function is an equivalent of  and is present  for compatibility only.  Deprecated. As of version 0.4, replaced by . O(n)H. Fold the keys and values in the map using the given right-associative 4 binary operator. This function is an equivalent of  and is present  for compatibility only. o56789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~     ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8  9  : ; < = > ? @ A B C D E F G H I J K L M NO !P"#$%&'()QRSTUDEFVG,-./WXYZ[\JK0]1^_2`a3bcdefgh4i5jklmn6opqrstuv9:wxyz;{|}~?<=>@ABHILMNP'(QRSTUVWXYZ]^_`abcdklmn6oqrsu~?@A !"#$%&'()0123*+45BCKJHI,-./689:;<=>?@ALMO !P"#$%&'()QRSTU0]1^_2`a3bcdYZ\[XWKJIH,-./ghef6opqrstuv4i5jklmnB9:wxyz;{|}~<=>?@ALMP'(QRSTU]^_`abcdYZXW6oqrsuklmn~?@A8&'SQ54?            8                                          ! " # $ % & ' ( )*+,-,./010234567 89:  ;   <!=>?@ABCDEF5GHIJKLMNOPQRSTUVWX YZ[\] ^_`abcdefghijklmnopqrstuvwxyz{|}5lGHIKLMNOPQR~+TU9 YZ efghijk[5GHI,<MB                        ! " # $ % & ' ( ) * + , - . /0containers-0.5.2.0Data.Set Data.Map.LazyData.Map.Strict Data.IntSetData.IntMap.StrictData.IntMap.Lazy Data.IntMap Data.Sequence Data.Tree Data.GraphData.MapData.StrictPair Data.Set.BasePreludefoldrfoldl Data.Map.BaseData.IntSet.BaseSetData.IntMap.BaselookupupdateLookupWithKeyMap insertWith insertWithKey Control.Monad replicateMinsertLookupWithKey\\nullsizemember notMemberlookupLTlookupGTlookupLElookupGEempty singletoninsertdeleteisProperSubsetOf isSubsetOffindMinfindMax deleteMin deleteMaxunionsunion difference intersectionfilter partitionmap mapMonotonicfoldfoldr'foldl'elemstoList toAscList toDescListfromList fromAscListfromDistinctAscListsplit splitMember findIndex lookupIndexelemAtdeleteAt deleteFindMin deleteFindMaxminViewmaxViewshowTree showTreeWithvalid!findWithDefaultadjust adjustWithKeyupdate updateWithKeyalterupdateAt updateMin updateMaxupdateMinWithKeyupdateMaxWithKeyminViewWithKeymaxViewWithKey unionsWith unionWith unionWithKeydifferenceWithdifferenceWithKeyintersectionWithintersectionWithKey mergeWithKey isSubmapOf isSubmapOfByisProperSubmapOfisProperSubmapOfBy filterWithKeypartitionWithKeymapMaybemapMaybeWithKey mapEithermapEitherWithKey mapWithKeytraverseWithKeymapAccummapAccumWithKeymapAccumRWithKeymapKeys mapKeysWithmapKeysMonotonic foldrWithKey foldrWithKey' foldlWithKey foldlWithKey'keysassocskeysSetfromSet fromListWithfromListWithKeyfromAscListWithfromAscListWithKey splitLookupKeyIntSetIntMap insertWith'insertWithKey' foldWithKeyViewR:>EmptyRViewL:<EmptyLSeq replicate replicateA<||>><unfoldrunfoldliterateNlengthviewlviewrscanlscanl1scanrscanr1index mapWithIndextakedropsplitAttailsinitsfoldlWithIndexfoldrWithIndex takeWhileL takeWhileR dropWhileL dropWhileRspanlspanrbreaklbreakr elemIndexL elemIndexR elemIndicesL elemIndicesR findIndexL findIndexR findIndicesL findIndicesRreversezipzipWithzip3zipWith3zip4zipWith4sortsortBy unstableSortunstableSortByForestTreeNode rootLabel subForestdrawTree drawForestflattenlevels unfoldTree unfoldForest unfoldTreeM unfoldForestMunfoldTreeM_BFunfoldForestM_BFEdgeBoundsGraphTableVertexSCC CyclicSCC AcyclicSCC flattenSCCs flattenSCCstronglyConnCompstronglyConnCompRverticesedgesbuildG transposeG outdegreeindegreegraphFromEdges'graphFromEdgesdffdfstopSort componentsscc reachablepathbccinsertLookupWithKey' StrictPair:*:toPairbaseGHC.Errerror Data.MaybeNothingghc-prim GHC.TypesTrueMaybeSJustSNothingSSizeTipBinfromListConstr setDataTypeinsertR isSubsetOfX hedgeUnion hedgeDiffhedgeIntfoldrFBfoldlFBtrimfilterGtfilterLtjoin insertMax insertMinmergegluedeltaratiobalanceLbalanceRbin foldlStrict showsTree showsTreeHangshowWide showsBarsnodewithBar withEmptyorderedbalanced validsize $fNFDataSet $fReadSet $fShowSet$fOrdSet$fEqSet $fDataSet $fFoldableSet $fMonoidSetJustfindGHC.BaseconstidFalse Data.EitherLeftRightData.Traversabletraverse mapAccumL Data.Tupleuncurry mapDataTypefirstsubmap' trimLookupLobalance $fShowMap $fReadMap $fNFDataMap $fFoldableMap$fTraversableMap $fFunctorMap$fOrdMap$fEqMap $fDataMap $fMonoidMapStackNadaPushBitMapMaskPrefixNilNat natFromInt intFromNatshiftRLshiftLLintSetDataType unsafeFindMin unsafeFindMaxinsertBMdeleteBM subsetCmpequalnequalshowBin showsBitMap showBitMaptip suffixBitMask prefixBitMaskprefixOfsuffixOfbitmapOfSuffixbitmapOfzeronomatchmatchmaskmaskWshorter branchMaskhighestBitMaskindexOfTheOnlyBit lowestBitMaskrevNat lowestBitSet highestBitSet foldlBits foldl'Bits foldrBits foldr'Bitsbitcount$fNFDataIntSet $fReadIntSet $fShowIntSet $fOrdIntSet $fEqIntSet $fDataIntSet$fMonoidIntSetintMapDataType mergeWithKey' submapCmp $fReadIntMap $fShowIntMap$fFunctorIntMap $fOrdIntMap $fEqIntMap $fDataIntMap$fNFDataIntMap$fTraversableIntMap$fFoldableIntMap$fMonoidIntMapPQueueState digitToTree' mapAccumL'applicativeTreeControl.Applicative Applicative<*>purefmap Data.Foldable tailsTree initsTreeFoldable fromList2unrollPQtoPQ FingerTreemergePQPQL:&SplitPlaceMaybe2Just2Nothing2runStateIdrunIdElemgetElemNode3Node2DigitFourThreeTwoOneDeepSingleEmptySized emptyConstr consConstr seqDataTypedeeppullLpullRdeepLdeepR digitToTreenode2node3 nodeToDigit execStateconsTreesnocTree appendTree0 addDigits0 appendTree1 addDigits1 appendTree2 addDigits2 appendTree3 addDigits3 appendTree4 addDigits4 viewLTree viewRTree lookupTree lookupNode lookupDigit adjustTree adjustNode adjustDigit splitTree splitNode splitDigit tailsDigit initsDigit tailsNode initsNode listToMaybe' reverseTree reverseDigit reverseNodezipWith'$fTraversableViewR$fFoldableViewR$fFunctorViewR$fTraversableViewL$fFoldableViewL$fFunctorViewL$fApplicativeState $fMonadState$fFunctorState$fApplicativeId $fMonadId $fFunctorId $fNFDataElem$fTraversableElem$fFoldableElem $fFunctorElem $fSizedElem $fSizedNode $fNFDataNode$fTraversableNode $fFunctorNode$fFoldableNode $fSizedDigit $fNFDataDigit$fTraversableDigit$fFunctorDigit$fFoldableDigit$fNFDataFingerTree$fTraversableFingerTree$fFunctorFingerTree$fFoldableFingerTree$fSizedFingerTree $fDataSeq $fMonoidSeq $fReadSeq $fShowSeq$fOrdSeq$fEqSeq$fAlternativeSeq$fMonadPlusSeq$fApplicativeSeq $fMonadSeq $fNFDataSeq$fTraversableSeq $fFoldableSeq $fFunctorSeqdraw unfoldForestQ $fNFDataTree$fFoldableTree$fTraversableTree $fMonadTree$fApplicativeTree $fFunctorTreeSetMrunSetMmapTreverseEgenerateprunechopruncontainsinclude preorder' preorderF' preorderFtabulatepreArr postorder postorderFpostOrd undirecteddo_labelbicompscollect $fMonadSetM $fNFDataSCC