From b2ee815b6b7ff54dfa924999d676086938ac73df Mon Sep 17 00:00:00 2001 From: meooow25 Date: Mon, 12 Aug 2024 20:54:21 +0530 Subject: [PATCH] Fix Map.Strict.mergeWithKey strictness Force the result of the combining function in mergeWithKey. --- containers/changelog.md | 5 +++++ containers/src/Data/Map/Strict/Internal.hs | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/containers/changelog.md b/containers/changelog.md index 0c19cd717..b6d2e786f 100644 --- a/containers/changelog.md +++ b/containers/changelog.md @@ -9,6 +9,11 @@ `Data.IntSet.splitMember` are now strict in the key. Previously, the key was ignored for an empty map or set. (Soumik Sarkar) +### Bug fixes + +* `Data.Map.Strict.mergeWithKey` now forces the result of the combining function + to WHNF. (Soumik Sarkar) + ## Unreleased with `@since` annotation for 0.7.1: ### Additions diff --git a/containers/src/Data/Map/Strict/Internal.hs b/containers/src/Data/Map/Strict/Internal.hs index 6b9093e37..2fe31145a 100644 --- a/containers/src/Data/Map/Strict/Internal.hs +++ b/containers/src/Data/Map/Strict/Internal.hs @@ -1250,7 +1250,7 @@ mergeWithKey f g1 g2 = go _ -> error "mergeWithKey: Given function only1 does not fulfill required conditions (see documentation)" Just x2 -> case f kx x x2 of Nothing -> link2 l' r' - Just x' -> link kx x' l' r' + Just !x' -> link kx x' l' r' where (l2, found, r2) = splitLookup kx t2 l' = go l1 l2