From 9cac37a09ac0bc69ba1bd5b157fe8fafcbcc4597 Mon Sep 17 00:00:00 2001 From: mniip Date: Thu, 21 Dec 2023 12:55:23 +0100 Subject: [PATCH] Work around a bug in mergeWithKey --- src/Data/IntMap/Common/Refined.hs | 9 +++++++-- src/Data/IntMap/Strict/Refined.hs | 11 +++++++++-- src/Data/Map/Common/Refined.hs | 9 +++++++-- src/Data/Map/Strict/Refined.hs | 9 +++++++-- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/Data/IntMap/Common/Refined.hs b/src/Data/IntMap/Common/Refined.hs index 5f2a692..6627133 100644 --- a/src/Data/IntMap/Common/Refined.hs +++ b/src/Data/IntMap/Common/Refined.hs @@ -241,8 +241,13 @@ zipWithKey -> IntMap s c zipWithKey f (IntMap m1) (IntMap m2) = IntMap $ IntMap.mergeWithKey (\k x y -> Just $ f (unsafeKey k) x y) - (error "zipWithKey: bug: Data.IntMap.Refined has been subverted") - (error "zipWithKey: bug: Data.IntMap.Refined has been subverted") + (\m -> if IntMap.null m + then IntMap.empty + else error "zipWithKey: bug: Data.IntMap.Refined has been subverted") + (\m -> if IntMap.null m + then IntMap.empty + else error "zipWithKey: bug: Data.IntMap.Refined has been subverted") + -- ^ Work around https://github.com/haskell/containers/issues/979 m1 m2 diff --git a/src/Data/IntMap/Strict/Refined.hs b/src/Data/IntMap/Strict/Refined.hs index dcd2f9e..d568b41 100644 --- a/src/Data/IntMap/Strict/Refined.hs +++ b/src/Data/IntMap/Strict/Refined.hs @@ -236,8 +236,15 @@ zipWithKey -> IntMap s c zipWithKey f (IntMap m1) (IntMap m2) = IntMap $ IntMap.mergeWithKey (\k x y -> Just $ f (unsafeKey k) x y) - (error "zipWithKey: bug: Data.IntMap.Strict.Refined has been subverted") - (error "zipWithKey: bug: Data.IntMap.Strict.Refined has been subverted") + (\m -> if IntMap.null m + then IntMap.empty + else + error "zipWithKey: bug: Data.IntMap.Strict.Refined has been subverted") + (\m -> if IntMap.null m + then IntMap.empty + else + error "zipWithKey: bug: Data.IntMap.Strict.Refined has been subverted") + -- ^ Work around https://github.com/haskell/containers/issues/979 m1 m2 diff --git a/src/Data/Map/Common/Refined.hs b/src/Data/Map/Common/Refined.hs index 14fdd5a..a9db9e1 100644 --- a/src/Data/Map/Common/Refined.hs +++ b/src/Data/Map/Common/Refined.hs @@ -241,8 +241,13 @@ zipWithKey => (Key s k -> a -> b -> c) -> Map s k a -> Map s k b -> Map s k c zipWithKey f (Map m1) (Map m2) = Map $ Map.mergeWithKey (\k x y -> Just $ f (unsafeKey k) x y) - (error "zipWithKey: bug: Data.Map.Refined has been subverted") - (error "zipWithKey: bug: Data.Map.Refined has been subverted") + (\m -> if Map.null m + then Map.empty + else error "zipWithKey: bug: Data.Map.Refined has been subverted") + (\m -> if Map.null m + then Map.empty + else error "zipWithKey: bug: Data.Map.Refined has been subverted") + -- ^ Work around https://github.com/haskell/containers/issues/979 m1 m2 diff --git a/src/Data/Map/Strict/Refined.hs b/src/Data/Map/Strict/Refined.hs index 2bac38d..ca48300 100644 --- a/src/Data/Map/Strict/Refined.hs +++ b/src/Data/Map/Strict/Refined.hs @@ -244,8 +244,13 @@ zipWithKey => (Key s k -> a -> b -> c) -> Map s k a -> Map s k b -> Map s k c zipWithKey f (Map m1) (Map m2) = Map $ Map.mergeWithKey (\k x y -> Just $ f (unsafeKey k) x y) - (error "zipWithKey: bug: Data.Map.Strict.Refined has been subverted") - (error "zipWithKey: bug: Data.Map.Strict.Refined has been subverted") + (\m -> if Map.null m + then Map.empty + else error "zipWithKey: bug: Data.Map.Strict.Refined has been subverted") + (\m -> if Map.null m + then Map.empty + else error "zipWithKey: bug: Data.Map.Strict.Refined has been subverted") + -- ^ Work around https://github.com/haskell/containers/issues/979 m1 m2