Skip to content

Commit a885c90

Browse files
tomjaguarpawtreeowl
authored andcommitted
Note that adjust = alter . fmap in Haddock
Proof: adjust satisfies adjust f k m = case lookup k m of Nothing -> m Just v -> insert k (f v) m and alter satisfies lookup k (alter f k m) = f (lookup k m) so lookup k (adjust f k m) == case lookup k m of Nothing -> lookup k m Just v -> lookup k (insert k (f v) m) == case lookup k m of Nothing -> Nothing Just v -> Just (f v) == fmap f (lookup k m) == lookup k (alter (fmap f) k m) == lookup k ((alter . fmap) f k m) A function is defined by its arguments and a Map is defined by its lookups, so this suffices to prove that `adjust == alter . fmap`.
1 parent 535384f commit a885c90

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

containers/src/Data/Map/Internal.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,8 @@ updateLookupWithKey f0 k0 = toPair . go f0 k0
11551155
-- > let f _ = Just "c"
11561156
-- > alter f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "c")]
11571157
-- > alter f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "c")]
1158+
--
1159+
-- Note that @'adjust' = alter . fmap@.
11581160

11591161
-- See Note: Type of local 'go' function
11601162
alter :: Ord k => (Maybe a -> Maybe a) -> k -> Map k a -> Map k a

containers/src/Data/Map/Strict/Internal.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,8 @@ updateLookupWithKey f0 k0 t0 = toPair $ go f0 k0 t0
795795
-- > let f _ = Just "c"
796796
-- > alter f 7 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "a"), (7, "c")]
797797
-- > alter f 5 (fromList [(5,"a"), (3,"b")]) == fromList [(3, "b"), (5, "c")]
798+
--
799+
-- Note that @'adjust' = alter . fmap@.
798800

799801
-- See Map.Internal.Note: Type of local 'go' function
800802
alter :: Ord k => (Maybe a -> Maybe a) -> k -> Map k a -> Map k a

0 commit comments

Comments
 (0)