Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions insert-ordered-containers.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: insert-ordered-containers
version: 0.2.1.0
x-revision: 5
version: 0.2.2.0
synopsis: Associative containers retaining insertion order for traversals.
description:
Associative containers retaining insertion order for traversals.
Expand Down Expand Up @@ -45,7 +44,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
Expand Down
40 changes: 40 additions & 0 deletions src/Data/HashMap/Strict/InsOrd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------------------------------------------------------------------------
Expand All @@ -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

Expand All @@ -157,6 +164,39 @@ 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

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
showsPrec d m = showParen (d > 10) $
showString "fromList " . showsPrec 11 (toList m)
Expand Down