@@ -38,26 +38,26 @@ empty = Leaf
3838singleton :: forall k v . k -> v -> Map k v
3939singleton k v = Branch { key: k, value: v, left: empty, right: empty }
4040
41- insert :: forall k v . (P.Eq k , P. Ord k ) => k -> v -> Map k v -> Map k v
41+ insert :: forall k v . (P.Ord k ) => k -> v -> Map k v -> Map k v
4242insert k v Leaf = singleton k v
4343insert k v (Branch b@{ key = k1 }) | k P .== k1 = Branch (b { key = k, value = v })
4444insert k v (Branch b@{ key = k1 }) | k P .< k1 = Branch (b { left = insert k v b.left })
4545insert k v (Branch b) = Branch (b { right = insert k v b.right })
4646
47- lookup :: forall k v . (P.Eq k , P. Ord k ) => k -> Map k v -> Maybe v
47+ lookup :: forall k v . (P.Ord k ) => k -> Map k v -> Maybe v
4848lookup k Leaf = Nothing
4949lookup k (Branch { key = k1, value = v }) | k P .== k1 = Just v
5050lookup k (Branch { key = k1, left = left }) | k P .< k1 = lookup k left
5151lookup k (Branch { right = right }) = lookup k right
5252
53- member :: forall k v . (P.Eq k , P. Ord k ) => k -> Map k v -> Boolean
53+ member :: forall k v . (P.Ord k ) => k -> Map k v -> Boolean
5454member k m = isJust (k `lookup` m)
5555
5656findMinKey :: forall k v . (P.Ord k ) => Map k v -> Tuple k v
5757findMinKey (Branch { key = k, value = v, left = Leaf }) = Tuple k v
5858findMinKey (Branch b) = findMinKey b.left
5959
60- delete :: forall k v . (P.Eq k , P. Ord k ) => k -> Map k v -> Map k v
60+ delete :: forall k v . (P.Ord k ) => k -> Map k v -> Map k v
6161delete k Leaf = Leaf
6262delete k (Branch b@{ key = k1, left = Leaf }) | k P .== k1 =
6363 case b of
@@ -67,7 +67,7 @@ delete k (Branch b@{ key = k1, left = Leaf }) | k P.== k1 =
6767delete k (Branch b@{ key = k1 }) | k P .< k1 = Branch (b { left = delete k b.left })
6868delete k (Branch b) = Branch (b { right = delete k b.right })
6969
70- alter :: forall k v . (P.Eq k , P. Ord k ) => (Maybe v -> Maybe v ) -> k -> Map k v -> Map k v
70+ alter :: forall k v . (P.Ord k ) => (Maybe v -> Maybe v ) -> k -> Map k v -> Map k v
7171alter f k Leaf = case f Nothing of
7272 Nothing -> Leaf
7373 Just v -> singleton k v
@@ -77,10 +77,10 @@ alter f k (Branch b@{ key = k1, value = v }) | k P.== k1 = case f (Just v) of
7777alter f k (Branch b@{ key = k1 }) | k P .< k1 = Branch (b { left = alter f k b.left })
7878alter f k (Branch b) = Branch (b { right = alter f k b.right })
7979
80- update :: forall k v . (P.Eq k , P. Ord k ) => (v -> Maybe v ) -> k -> Map k v -> Map k v
80+ update :: forall k v . (P.Ord k ) => (v -> Maybe v ) -> k -> Map k v -> Map k v
8181update f k m = alter (maybe Nothing f) k m
8282
83- glue :: forall k v . (P.Eq k , P. Ord k ) => Map k v -> Map k v -> Map k v
83+ glue :: forall k v . (P.Ord k ) => Map k v -> Map k v -> Map k v
8484glue left right =
8585 case findMinKey right of
8686 Tuple minKey root -> Branch { key: minKey, value: root, left: left, right: delete minKey right }
@@ -89,7 +89,7 @@ toList :: forall k v. Map k v -> [Tuple k v]
8989toList Leaf = []
9090toList (Branch b) = toList b.left P .++ [Tuple b.key b.value] P .++ toList b.right
9191
92- fromList :: forall k v . (P.Eq k , P. Ord k ) => [Tuple k v ] -> Map k v
92+ fromList :: forall k v . (P.Ord k ) => [Tuple k v ] -> Map k v
9393fromList = foldl (\m (Tuple k v) -> insert k v m) empty
9494
9595keys :: forall k v . Map k v -> [k ]
@@ -100,9 +100,9 @@ values :: forall k v. Map k v -> [v]
100100values Leaf = []
101101values (Branch b) = values b.left P .++ [b.value] P .++ values b.right
102102
103- union :: forall k v . (P.Eq k , P. Ord k ) => Map k v -> Map k v -> Map k v
103+ union :: forall k v . (P.Ord k ) => Map k v -> Map k v -> Map k v
104104union m1 m2 = foldl (\m (Tuple k v) -> insert k v m) m2 (toList m1)
105105
106- map :: forall k v1 v2 . (P.Eq k , P. Ord k ) => (v1 -> v2 ) -> Map k v1 -> Map k v2
106+ map :: forall k v1 v2 . (P.Ord k ) => (v1 -> v2 ) -> Map k v1 -> Map k v2
107107map _ Leaf = Leaf
108108map f (Branch b) = Branch (b { value = f b.value, left = map f b.left, right = map f b.right })
0 commit comments