Skip to content

Commit 94969c3

Browse files
Support containers-0.8 in combineEq.
This commit provides a workaround for a change in the behaviour of `Set.from{Asc,Desc}List` w.r.t. duplicate elements, when upgrading from `containers-0.7` to `containers-0.8`. We can use the `K` type from `Tests.Util` to demonstrate this. With `containers-0.7`, `Set.from{Asc,Desc}List` chooses the **_first_** occurrence of any duplicated element: ```hs $ cabal repl nonempty-containers-test --constraint=containers==0.7 > import qualified Data.Set as Set > import Tests.Util > Set.fromAscList [K 'a' 1, K 'a' 2] fromList [K {getKX = 'a', getKY = 1}] > Set.fromDescList [K 'a' 1, K 'a' 2] fromList [K {getKX = 'a', getKY = 1}] ``` With `containers-0.8`, `Set.from{Asc,Desc}List` chooses the **_last_** occurrence of any duplicated element: ```hs $ cabal repl nonempty-containers-test --constraint=containers==0.8 > import qualified Data.Set as Set > import Tests.Util > Set.fromAscList [K 'a' 1, K 'a' 2] fromList [K {getKX = 'a', getKY = 2}] > Set.fromDescList [K 'a' 1, K 'a' 2] fromList [K {getKX = 'a', getKY = 2}] ``` This commit adjusts the bias of `Data.Set.NonEmpty.combineEq` to match the bias of `Set.from{Asc,Desc}List` in the version of `containers` being linked against.
1 parent 747201b commit 94969c3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Data/Set/NonEmpty.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE BangPatterns #-}
2+
{-# LANGUAGE CPP #-}
23
{-# LANGUAGE PatternSynonyms #-}
34
{-# LANGUAGE ScopedTypeVariables #-}
45
{-# LANGUAGE TupleSections #-}
@@ -1054,5 +1055,9 @@ combineEq (x :| xs) = go x xs
10541055
where
10551056
go z [] = z :| []
10561057
go z (y : ys)
1058+
#if MIN_VERSION_containers(0,8,0)
1059+
| z == y = go y ys
1060+
#else
10571061
| z == y = go z ys
1062+
#endif
10581063
| otherwise = z NE.<| go y ys

0 commit comments

Comments
 (0)