Remove redundant Ord constraints.
authorJulien Moutinho <julm+haskell+treemap@autogeree.net>
Sat, 10 Dec 2016 22:13:58 +0000 (23:13 +0100)
committerJulien Moutinho <julm+haskell+treemap@autogeree.net>
Sat, 10 Dec 2016 22:13:58 +0000 (23:13 +0100)
Data/TreeMap/Strict.hs
Data/TreeMap/Strict/Zipper.hs

index 7ebd52cc83076932618c0f7d7401274d482786e1..948b24492c3617178bc187b8eae8c17e82ca027c 100644 (file)
@@ -22,7 +22,7 @@ import qualified Data.List
 import qualified Data.List.NonEmpty
 import           Data.List.NonEmpty (NonEmpty(..))
 import           Data.Map.Strict (Map)
-import qualified Data.Map.Strict as Data.Map
+import qualified Data.Map.Strict as Map
 import           Data.Maybe (Maybe(..), maybe)
 import           Data.Monoid (Monoid(..))
 import           Data.Ord (Ord(..))
@@ -129,20 +129,20 @@ node_find :: Ord k => [k] -> Node k x -> Strict.Maybe (Node k x)
 node_find [] n = Strict.Just n
 node_find (k:ks) Node{node_descendants=TreeMap m} =
        maybe Strict.Nothing (node_find ks) $
-       Data.Map.lookup k m
+       Map.lookup k m
 
 -- * Construct
 
 -- | Return the empty 'TreeMap'.
-empty :: Ord k => TreeMap k x
-empty = TreeMap Data.Map.empty
+empty :: TreeMap k x
+empty = TreeMap Map.empty
 
 -- | Return a 'TreeMap' only mapping the given 'Path' to the given value.
 singleton :: Ord k => Path k -> x -> TreeMap k x
 singleton ks x = insert const ks x empty
 
 -- | Return a 'Node' only containing the given value.
-leaf :: Ord k => x -> Node k x
+leaf :: x -> Node k x
 leaf x =
        Node
         { node_value = Strict.Just x
@@ -156,7 +156,7 @@ leaf x =
 insert :: Ord k => (x -> x -> x) -> Path k -> x -> TreeMap k x -> TreeMap k x
 insert merge (k:|[]) x (TreeMap m) =
        TreeMap $
-       Data.Map.insertWith
+       Map.insertWith
         (\_ Node{node_value = x1, node_descendants = m1, node_size = s1} ->
                Node
                 { node_value = Strict.maybe (Strict.Just x) (Strict.Just . merge x) x1
@@ -166,7 +166,7 @@ insert merge (k:|[]) x (TreeMap m) =
         k (leaf x) m
 insert merge (k:|k':ks) x (TreeMap m) =
        TreeMap $
-       Data.Map.insertWith
+       Map.insertWith
         (\_ Node{node_value = x1, node_descendants = m1} ->
                let m' = insert merge (path k' ks) x m1 in
                let s' = size m' + Strict.maybe 0 (const 1) x1 in
@@ -189,32 +189,32 @@ from_List merge = Data.List.foldl (\acc (p, x) -> insert merge p x acc) empty
 -- the 'Path' to the value,
 -- merging values of identical 'Path's (in respective order).
 from_Map :: Ord k => (x -> x -> x) -> Map (Path k) x -> TreeMap k x
-from_Map merge = Data.Map.foldlWithKey (\acc p x -> insert merge p x acc) empty
+from_Map merge = Map.foldlWithKey (\acc p x -> insert merge p x acc) empty
 
 -- * Size
 
 -- | Return the 'Map' in the given 'TreeMap'.
-nodes :: Ord k => TreeMap k x -> Map k (Node k x)
+nodes :: TreeMap k x -> Map k (Node k x)
 nodes (TreeMap m) = m
 
 -- | Return 'True' iif. the given 'TreeMap' is 'empty'.
-null :: Ord k => TreeMap k x -> Bool
-null (TreeMap m) = Data.Map.null m
+null :: TreeMap k x -> Bool
+null (TreeMap m) = Map.null m
 
 -- | Return the number of non-'Strict.Nothing' 'node_value's in the given 'TreeMap'.
 --
 --   * Complexity: O(r) where r is the size of the root 'Map'.
-size :: Ord k => TreeMap k x -> Int
-size = Data.Map.foldr ((+) . node_size) 0 . nodes
+size :: TreeMap k x -> Int
+size = Map.foldr ((+) . node_size) 0 . nodes
 
 -- * Find
 
 -- | Return the value (if any) associated with the given 'Path'.
 find :: Ord k => Path k -> TreeMap k x -> Strict.Maybe x
-find (k:|[]) (TreeMap m) = maybe Strict.Nothing node_value $ Data.Map.lookup k m
+find (k:|[]) (TreeMap m) = maybe Strict.Nothing node_value $ Map.lookup k m
 find (k:|k':ks) (TreeMap m) =
        maybe Strict.Nothing (find (path k' ks) . node_descendants) $
-       Data.Map.lookup k m
+       Map.lookup k m
 
 -- | Return the values (if any) associated with the prefixes of the given 'Path' (included).
 find_along :: Ord k => Path k -> TreeMap k x -> [x]
@@ -224,17 +224,17 @@ find_along p (TreeMap tm) =
                go :: Ord k => [k] -> Map k (Node k x) -> [x]
                go [] _m = []
                go (k:ks) m =
-                       case Data.Map.lookup k m of
+                       case Map.lookup k m of
                         Nothing -> []
                         Just node ->
                                Strict.maybe id (:) (node_value node) $
                                go ks $ nodes (node_descendants node)
 
 find_node :: Ord k => Path k -> TreeMap k x -> Strict.Maybe (Node k x)
-find_node (k:|[]) (TreeMap m) = maybe Strict.Nothing Strict.Just $ Data.Map.lookup k m
+find_node (k:|[]) (TreeMap m) = maybe Strict.Nothing Strict.Just $ Map.lookup k m
 find_node (k:|k':ks) (TreeMap m) =
        maybe Strict.Nothing (find_node (path k' ks) . node_descendants) $
-       Data.Map.lookup k m
+       Map.lookup k m
 
 -- * Union
 
@@ -244,7 +244,7 @@ find_node (k:|k':ks) (TreeMap m) =
 union :: Ord k => (x -> x -> x) -> TreeMap k x -> TreeMap k x -> TreeMap k x
 union merge (TreeMap tm0) (TreeMap tm1) =
        TreeMap $
-       Data.Map.unionWith
+       Map.unionWith
         (\Node{node_value=x0, node_descendants=m0}
           Node{node_value=x1, node_descendants=m1} ->
                let node_descendants = union merge m0 m1 in
@@ -275,7 +275,7 @@ unions merge = Data.List.foldl' (union merge) empty
 map :: Ord k => (x -> y) -> TreeMap k x -> TreeMap k y
 map f =
        TreeMap .
-       Data.Map.map
+       Map.map
         (\n@Node{node_value=x, node_descendants=m} ->
                n{ node_value       = fmap f x
                 , node_descendants = map f m
@@ -287,12 +287,12 @@ map f =
 -- mapped by the given functions.
 --
 -- WARNING: the function mapping 'Path' sections must be monotonic,
--- like in 'Data.Map.mapKeysMonotonic'.
+-- like in 'Map.mapKeysMonotonic'.
 map_monotonic :: (Ord k, Ord l) => (k -> l) -> (x -> y) -> TreeMap k x -> TreeMap l y
 map_monotonic fk fx =
        TreeMap .
-       Data.Map.mapKeysMonotonic fk .
-       Data.Map.map
+       Map.mapKeysMonotonic fk .
+       Map.map
         (\n@Node{node_value=x, node_descendants=m} ->
                n{ node_value       = fmap fx x
                 , node_descendants = map_monotonic fk fx m
@@ -305,7 +305,7 @@ map_monotonic fk fx =
 map_by_depth_first :: Ord k => (TreeMap k y -> Strict.Maybe x -> y) -> TreeMap k x -> TreeMap k y
 map_by_depth_first f =
        TreeMap .
-       Data.Map.map
+       Map.map
         (\Node{node_value, node_descendants} ->
                let m = map_by_depth_first f node_descendants in
                Node
@@ -327,7 +327,7 @@ alterl_path fct =
                go _f [] m = m
                go f (k:p) (TreeMap m) =
                        TreeMap $
-                       Data.Map.alter
+                       Map.alter
                         (\c ->
                                let (cv, cm) =
                                        case c of
@@ -358,7 +358,7 @@ foldl_with_Path =
                 => [k] -> (a -> Path k -> x -> a)
                 -> a -> TreeMap k x -> a
                foldp p fct a (TreeMap m) =
-                       Data.Map.foldlWithKey
+                       Map.foldlWithKey
                         (\acc k Node{node_value, node_descendants} ->
                                let acc' = Strict.maybe acc (fct acc (reverse $ path k p)) node_value in
                                foldp (k:p) fct acc' node_descendants) a m
@@ -374,7 +374,7 @@ foldl_with_Path_and_Node =
                 => [k] -> (a -> Node k x -> Path k -> x -> a)
                 -> a -> TreeMap k x -> a
                foldp p fct a (TreeMap m) =
-                       Data.Map.foldlWithKey
+                       Map.foldlWithKey
                         (\acc k n@Node{node_value, node_descendants} ->
                                let acc' = Strict.maybe acc (fct acc n (reverse $ path k p)) node_value in
                                foldp (k:p) fct acc' node_descendants) a m
@@ -390,7 +390,7 @@ foldr_with_Path =
                 => [k] -> (Path k -> x -> a -> a)
                 -> a -> TreeMap k x -> a
                foldp p fct a (TreeMap m) =
-                       Data.Map.foldrWithKey
+                       Map.foldrWithKey
                         (\k Node{node_value, node_descendants} acc ->
                                let acc' = foldp (k:p) fct acc node_descendants in
                                Strict.maybe acc' (\x -> fct (reverse $ path k p) x acc') node_value) a m
@@ -406,7 +406,7 @@ foldr_with_Path_and_Node =
                 => [k] -> (Node k x -> Path k -> x -> a -> a)
                 -> a -> TreeMap k x -> a
                foldp p fct a (TreeMap m) =
-                       Data.Map.foldrWithKey
+                       Map.foldrWithKey
                         (\k n@Node{node_value, node_descendants} acc ->
                                let acc' = foldp (k:p) fct acc node_descendants in
                                Strict.maybe acc' (\x -> fct n (reverse $ path k p) x acc') node_value) a m
@@ -423,7 +423,7 @@ foldl_path fct =
                 -> TreeMap k x -> a -> a
                go _f _ [] _t a = a
                go f p (k:n) (TreeMap t) a =
-                       case Data.Map.lookup k t of
+                       case Map.lookup k t of
                         Nothing -> a
                         Just Node{node_value=v, node_descendants=d} ->
                                case v of
@@ -442,7 +442,7 @@ foldr_path fct =
                 -> TreeMap k x -> a -> a
                go _f _ [] _t a = a
                go f p (k:n) (TreeMap t) a =
-                       case Data.Map.lookup k t of
+                       case Map.lookup k t of
                         Nothing -> a
                         Just Node{node_value=v, node_descendants=d} ->
                                case v of
@@ -467,14 +467,14 @@ flatten_with_Path =
                 -> TreeMap k x
                 -> Map (Path k) y
                flat_map p f (TreeMap m) =
-                       Data.Map.unions $
-                       Data.Map.mapKeysMonotonic (reverse . flip path p) (
-                       Data.Map.mapMaybeWithKey (\k Node{node_value} ->
+                       Map.unions $
+                       Map.mapKeysMonotonic (reverse . flip path p) (
+                       Map.mapMaybeWithKey (\k Node{node_value} ->
                                case node_value of
                                 Strict.Nothing -> Nothing
                                 Strict.Just x  -> Just $ f (reverse $ path k p) x) m
                        ) :
-                       Data.Map.foldrWithKey
+                       Map.foldrWithKey
                         (\k -> (:) . flat_map (k:p) f . node_descendants)
                         [] m
 
@@ -521,7 +521,7 @@ map_Maybe_with_Path_and_Node =
                 -> TreeMap k y
                go p test (TreeMap m) =
                        TreeMap $
-                       Data.Map.mapMaybeWithKey
+                       Map.mapMaybeWithKey
                         (\k node@Node{node_value=v, node_descendants=ns} ->
                                let node_descendants = go (k:p) test ns in
                                let node_size = size node_descendants in
index 297b2f7f2653a69d919be4e91f1358020da06c4d..256a61ed235b5e4ef3590fa190c8a35e741e516a 100644 (file)
@@ -58,7 +58,7 @@ zipper_collect_without_self f z = maybe [] (zipper_collect f) (f z)
 
 -- ** Axis self
 
-zipper_self :: Ord k => Zipper k x -> Maybe (k, TreeMap.Node k x)
+zipper_self :: Zipper k x -> Maybe (k, TreeMap.Node k x)
 zipper_self z =
        case z of
         Zipper{ zipper_path=
@@ -83,7 +83,7 @@ zipper_child_at k (Zipper path (TreeMap m)) =
                 , zipper_curr = TreeMap.node_descendants s
                 }
 
-zipper_child_first :: Ord k => Zipper k x -> Maybe (Zipper k x)
+zipper_child_first :: Zipper k x -> Maybe (Zipper k x)
 zipper_child_first (Zipper path (TreeMap m)) =
        case Map.minViewWithKey m of
         Nothing -> Nothing
@@ -93,7 +93,7 @@ zipper_child_first (Zipper path (TreeMap m)) =
                 , zipper_curr = TreeMap.node_descendants s'
                 }
 
-zipper_child_last :: Ord k => Zipper k x -> Maybe (Zipper k x)
+zipper_child_last :: Zipper k x -> Maybe (Zipper k x)
 zipper_child_last (Zipper path (TreeMap m)) =
        case Map.maxViewWithKey m of
         Nothing -> Nothing