From 4435fc774a32ccf0b87890e6ba652360fdb40b30 Mon Sep 17 00:00:00 2001 From: Doug Beardsley Date: Thu, 5 Apr 2018 10:43:39 -0600 Subject: [PATCH 1/4] Add missing Ord and Eq instances --- insert-ordered-containers.cabal | 2 +- src/Data/HashMap/Strict/InsOrd.hs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/insert-ordered-containers.cabal b/insert-ordered-containers.cabal index 6cc0026..38b0c2a 100644 --- a/insert-ordered-containers.cabal +++ b/insert-ordered-containers.cabal @@ -45,7 +45,7 @@ library , semigroups >=0.16.2.2 && <0.19 , text >=1.2.0.6 && <1.3 , transformers >=0.3.0.0 && <0.6 - , unordered-containers >=0.2.7.0 && <0.3 + , unordered-containers >=0.2.9.0 && <0.3 exposed-modules: Data.HashMap.Strict.InsOrd default-language: Haskell2010 diff --git a/src/Data/HashMap/Strict/InsOrd.hs b/src/Data/HashMap/Strict/InsOrd.hs index 5b98107..a542e95 100644 --- a/src/Data/HashMap/Strict/InsOrd.hs +++ b/src/Data/HashMap/Strict/InsOrd.hs @@ -114,6 +114,10 @@ import qualified Data.HashMap.Strict as HashMap import qualified GHC.Exts as Exts #endif +#if MIN_VERSION_base(4,9,0) +import Data.Functor.Classes +#endif + ------------------------------------------------------------------------------- -- Strict Pair Int a ------------------------------------------------------------------------------- @@ -136,6 +140,9 @@ incPK i (P j x) = P (i + j) x instance Eq a => Eq (P a) where P _ a == P _ b = a == b +instance Ord a => Ord (P a) where + compare (P _ a) (P _ b) = compare a b + instance Show a => Show (P a) where showsPrec d (P _ x) = showsPrec d x @@ -157,6 +164,29 @@ data InsOrdHashMap k v = InsOrdHashMap instance (Eq k, Eq v) => Eq (InsOrdHashMap k v) where InsOrdHashMap _ a == InsOrdHashMap _ b = a == b +instance (Ord k, Ord v) => Ord (InsOrdHashMap k v) where + compare (InsOrdHashMap _ a) (InsOrdHashMap _ b) = compare a b + +#if MIN_VERSION_base(4,9,0) +liftP :: (t1 -> t2 -> t3) -> P t1 -> P t2 -> t3 +liftP f pa pb = f (getPV pa) (getPV pb) + +instance Eq k => Eq1 (InsOrdHashMap k) where + liftEq f (InsOrdHashMap _ a) (InsOrdHashMap _ b) = liftEq (liftP f) a b + +instance Eq2 InsOrdHashMap where + liftEq2 f g (InsOrdHashMap _ a) (InsOrdHashMap _ b) = + liftEq2 f (liftP g) a b + +instance Ord k => Ord1 (InsOrdHashMap k) where + liftCompare f (InsOrdHashMap _ a) (InsOrdHashMap _ b) = + liftCompare (liftP f) a b + +instance Ord2 InsOrdHashMap where + liftCompare2 f g (InsOrdHashMap _ a) (InsOrdHashMap _ b) = + liftCompare2 f (liftP g) a b +#endif + instance (Show k, Show v) => Show (InsOrdHashMap k v) where showsPrec d m = showParen (d > 10) $ showString "fromList " . showsPrec 11 (toList m) From 842b32c012e01ba1930c34c367dab9a9412c332d Mon Sep 17 00:00:00 2001 From: Doug Beardsley Date: Thu, 5 Apr 2018 11:28:34 -0600 Subject: [PATCH 2/4] Version bump --- insert-ordered-containers.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/insert-ordered-containers.cabal b/insert-ordered-containers.cabal index 38b0c2a..97f6469 100644 --- a/insert-ordered-containers.cabal +++ b/insert-ordered-containers.cabal @@ -1,5 +1,5 @@ name: insert-ordered-containers -version: 0.2.1.0 +version: 0.2.2.0 x-revision: 5 synopsis: Associative containers retaining insertion order for traversals. description: From 2a15aea6a9733259ee494eb379dd4df206d215c5 Mon Sep 17 00:00:00 2001 From: Doug Beardsley Date: Thu, 5 Apr 2018 13:59:47 -0600 Subject: [PATCH 3/4] Remove x-revision field --- insert-ordered-containers.cabal | 1 - 1 file changed, 1 deletion(-) diff --git a/insert-ordered-containers.cabal b/insert-ordered-containers.cabal index 97f6469..0b39efb 100644 --- a/insert-ordered-containers.cabal +++ b/insert-ordered-containers.cabal @@ -1,6 +1,5 @@ name: insert-ordered-containers version: 0.2.2.0 -x-revision: 5 synopsis: Associative containers retaining insertion order for traversals. description: Associative containers retaining insertion order for traversals. From 87054c519b969b62131bcf7a183470d422cbb535 Mon Sep 17 00:00:00 2001 From: Doug Beardsley Date: Thu, 5 Apr 2018 14:45:00 -0600 Subject: [PATCH 4/4] Add Show1 and Show2 instances --- src/Data/HashMap/Strict/InsOrd.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Data/HashMap/Strict/InsOrd.hs b/src/Data/HashMap/Strict/InsOrd.hs index a542e95..a594e7d 100644 --- a/src/Data/HashMap/Strict/InsOrd.hs +++ b/src/Data/HashMap/Strict/InsOrd.hs @@ -185,6 +185,16 @@ instance Ord k => Ord1 (InsOrdHashMap k) where instance Ord2 InsOrdHashMap where liftCompare2 f g (InsOrdHashMap _ a) (InsOrdHashMap _ b) = liftCompare2 f (liftP g) a b + +instance Show2 InsOrdHashMap where + liftShowsPrec2 spk slk spv slv d m = + showsUnaryWith (liftShowsPrec sp sl) "fromList" d (toList m) + where + sp = liftShowsPrec2 spk slk spv slv + sl = liftShowList2 spk slk spv slv + +instance Show k => Show1 (InsOrdHashMap k) where + liftShowsPrec = liftShowsPrec2 showsPrec showList #endif instance (Show k, Show v) => Show (InsOrdHashMap k v) where