@@ -27,14 +27,14 @@ module Data.Map
2727 , size
2828 ) where
2929
30- import Prelude
30+ import Prelude ( class Ord , class Show , class Functor , class Semigroup , class Eq , (<<<), const , pure , ($), otherwise , (<), (&&), (==), one , (+), map , zero , show , id , (<$>), (<*>), compare , Ordering (..), append )
3131
32- import Data.Foldable (foldl , foldMap , foldr , Foldable )
32+ import Data.Foldable (foldl , foldMap , foldr , class Foldable )
3333import Data.List (List (..), length , nub )
3434import Data.Maybe (Maybe (..), maybe , isJust )
3535import Data.Maybe.Unsafe (unsafeThrow )
36- import Data.Monoid (Monoid )
37- import Data.Traversable (traverse , Traversable )
36+ import Data.Monoid (class Monoid )
37+ import Data.Traversable (traverse , class Traversable )
3838import Data.Tuple (Tuple (..), uncurry )
3939
4040-- | `Map k v` represents maps from keys of type `k` to values of type `v`.
@@ -47,7 +47,7 @@ instance eqMap :: (Eq k, Eq v) => Eq (Map k v) where
4747 eq m1 m2 = toList m1 == toList m2
4848
4949instance showMap :: (Show k , Show v ) => Show (Map k v ) where
50- show m = " fromList " ++ show (toList m)
50+ show m = " fromList " `append` show (toList m)
5151
5252instance ordMap :: (Ord k , Ord v ) => Ord (Map k v ) where
5353 compare m1 m2 = compare (toList m1) (toList m2)
@@ -76,18 +76,18 @@ instance traversableMap :: (Ord k) => Traversable (Map k) where
7676showTree :: forall k v . (Show k , Show v ) => Map k v -> String
7777showTree Leaf = " Leaf"
7878showTree (Two left k v right) =
79- " Two (" ++ showTree left ++
80- " ) (" ++ show k ++
81- " ) (" ++ show v ++
82- " ) (" ++ showTree right ++ " )"
79+ " Two (" `append` showTree left `append`
80+ " ) (" `append` show k `append`
81+ " ) (" `append` show v `append`
82+ " ) (" `append` showTree right `append` " )"
8383showTree (Three left k1 v1 mid k2 v2 right) =
84- " Three (" ++ showTree left ++
85- " ) (" ++ show k1 ++
86- " ) (" ++ show v1 ++
87- " ) (" ++ showTree mid ++
88- " ) (" ++ show k2 ++
89- " ) (" ++ show v2 ++
90- " ) (" ++ showTree right ++ " )"
84+ " Three (" `append` showTree left `append`
85+ " ) (" `append` show k1 `append`
86+ " ) (" `append` show v1 `append`
87+ " ) (" `append` showTree mid `append`
88+ " ) (" `append` show k2 `append`
89+ " ) (" `append` show v2 `append`
90+ " ) (" `append` showTree right `append` " )"
9191
9292-- | An empty map
9393empty :: forall k v . Map k v
@@ -110,8 +110,8 @@ checkValid tree = length (nub (allHeights tree)) == one
110110 where
111111 allHeights :: Map k v -> List Int
112112 allHeights Leaf = pure zero
113- allHeights (Two left _ _ right) = map (\n -> n + one) (allHeights left ++ allHeights right)
114- allHeights (Three left _ _ mid _ _ right) = map (\n -> n + one) (allHeights left ++ allHeights mid ++ allHeights right)
113+ allHeights (Two left _ _ right) = map (\n -> n + one) (allHeights left `append` allHeights right)
114+ allHeights (Three left _ _ mid _ _ right) = map (\n -> n + one) (allHeights left `append` allHeights mid `append` allHeights right)
115115
116116-- | Lookup a value for the specified key
117117lookup :: forall k v . (Ord k ) => k -> Map k v -> Maybe v
@@ -288,8 +288,8 @@ fromFoldableWith f = foldl (\m (Tuple k v) -> alter (combine v) k m) empty where
288288-- | Convert a map to a list of key/value pairs
289289toList :: forall k v . Map k v -> List (Tuple k v )
290290toList Leaf = Nil
291- toList (Two left k v right) = toList left ++ pure (Tuple k v) ++ toList right
292- toList (Three left k1 v1 mid k2 v2 right) = toList left ++ pure (Tuple k1 v1) ++ toList mid ++ pure (Tuple k2 v2) ++ toList right
291+ toList (Two left k v right) = toList left `append` pure (Tuple k v) `append` toList right
292+ toList (Three left k1 v1 mid k2 v2 right) = toList left `append` pure (Tuple k1 v1) `append` toList mid `append` pure (Tuple k2 v2) `append` toList right
293293
294294-- | Create a map from a list of key/value pairs
295295fromList :: forall k v . (Ord k ) => List (Tuple k v ) -> Map k v
@@ -303,14 +303,14 @@ fromListWith = fromFoldableWith
303303-- | Get a list of the keys contained in a map
304304keys :: forall k v . Map k v -> List k
305305keys Leaf = Nil
306- keys (Two left k _ right) = keys left ++ pure k ++ keys right
307- keys (Three left k1 _ mid k2 _ right) = keys left ++ pure k1 ++ keys mid ++ pure k2 ++ keys right
306+ keys (Two left k _ right) = keys left `append` pure k `append` keys right
307+ keys (Three left k1 _ mid k2 _ right) = keys left `append` pure k1 `append` keys mid `append` pure k2 `append` keys right
308308
309309-- | Get a list of the values contained in a map
310310values :: forall k v . Map k v -> List v
311311values Leaf = Nil
312- values (Two left _ v right) = values left ++ pure v ++ values right
313- values (Three left _ v1 mid _ v2 right) = values left ++ pure v1 ++ values mid ++ pure v2 ++ values right
312+ values (Two left _ v right) = values left `append` pure v `append` values right
313+ values (Three left _ v1 mid _ v2 right) = values left `append` pure v1 `append` values mid `append` pure v2 `append` values right
314314
315315-- | Compute the union of two maps, using the specified function
316316-- | to combine values for duplicate keys.
0 commit comments