From 4a08e80ea471796ec4ba0da80c8b306b27b83b04 Mon Sep 17 00:00:00 2001 From: Georgi Lyubenov Date: Tue, 15 Aug 2023 18:22:05 +0300 Subject: [PATCH 1/2] Add Ord instances for Interval, IntervalSet and IntervalMap The primary intended use case for these is to allow storage in maps and sets. --- src/Data/Interval/Internal.hs | 9 ++++++++- src/Data/IntervalMap/Base.hs | 9 ++++++++- src/Data/IntervalSet.hs | 9 ++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Data/Interval/Internal.hs b/src/Data/Interval/Internal.hs index c34876d..00db496 100644 --- a/src/Data/Interval/Internal.hs +++ b/src/Data/Interval/Internal.hs @@ -50,7 +50,14 @@ data Interval r | LeftOpen !r !r | RightOpen !r !r | BothOpen !r !r - deriving (Eq, Typeable) + deriving + ( Eq, + Ord, + -- ^ Note that this Ord is derived and not semantically meaningful. + -- The primary intended use case is to allow using 'Interval' + -- in maps and sets that require ordering. + Typeable + ) peekInterval :: (Applicative m, Monad m, Ord r) => m Int8 -> m r -> m r -> m (Interval r) peekInterval tagM x y = do diff --git a/src/Data/IntervalMap/Base.hs b/src/Data/IntervalMap/Base.hs index 44a6d2e..76f049f 100644 --- a/src/Data/IntervalMap/Base.hs +++ b/src/Data/IntervalMap/Base.hs @@ -115,7 +115,14 @@ import qualified GHC.Exts as GHCExts -- Unlike 'IntervalSet', 'IntervalMap' never merge adjacent mappings, -- even if adjacent intervals are connected and mapped to the same value. newtype IntervalMap r a = IntervalMap (Map (LB r) (Interval r, a)) - deriving (Eq, Typeable) + deriving + ( Eq, + Ord, + -- ^ Note that this Ord is derived and not semantically meaningful. + -- The primary intended use case is to allow using 'IntervalSet' + -- in maps and sets that require ordering. + Typeable + ) type role IntervalMap nominal representational diff --git a/src/Data/IntervalSet.hs b/src/Data/IntervalSet.hs index 182ff5e..1092634 100644 --- a/src/Data/IntervalSet.hs +++ b/src/Data/IntervalSet.hs @@ -84,7 +84,14 @@ import qualified GHC.Exts as GHCExts -- -- Any connected intervals are merged together, and empty intervals are ignored. newtype IntervalSet r = IntervalSet (Map (Extended r) (Interval r)) - deriving (Eq, Typeable) + deriving + ( Eq, + Ord, + -- ^ Note that this Ord is derived and not semantically meaningful. + -- The primary intended use case is to allow using 'IntervalSet' + -- in maps and sets that require ordering. + Typeable + ) type role IntervalSet nominal From 9b1cfd029ed8979e7629923b5617406f737c30b7 Mon Sep 17 00:00:00 2001 From: Masahiro Sakai Date: Mon, 11 Sep 2023 13:07:33 +0300 Subject: [PATCH 2/2] Fix CI on 8.10.7 --- src/Data/Interval/Internal.hs | 6 +++--- src/Data/IntervalMap/Base.hs | 6 +++--- src/Data/IntervalSet.hs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Data/Interval/Internal.hs b/src/Data/Interval/Internal.hs index 00db496..9c8e3e6 100644 --- a/src/Data/Interval/Internal.hs +++ b/src/Data/Interval/Internal.hs @@ -51,12 +51,12 @@ data Interval r | RightOpen !r !r | BothOpen !r !r deriving - ( Eq, - Ord, + ( Eq + , Ord -- ^ Note that this Ord is derived and not semantically meaningful. -- The primary intended use case is to allow using 'Interval' -- in maps and sets that require ordering. - Typeable + , Typeable ) peekInterval :: (Applicative m, Monad m, Ord r) => m Int8 -> m r -> m r -> m (Interval r) diff --git a/src/Data/IntervalMap/Base.hs b/src/Data/IntervalMap/Base.hs index 76f049f..7f0dac6 100644 --- a/src/Data/IntervalMap/Base.hs +++ b/src/Data/IntervalMap/Base.hs @@ -116,12 +116,12 @@ import qualified GHC.Exts as GHCExts -- even if adjacent intervals are connected and mapped to the same value. newtype IntervalMap r a = IntervalMap (Map (LB r) (Interval r, a)) deriving - ( Eq, - Ord, + ( Eq + , Ord -- ^ Note that this Ord is derived and not semantically meaningful. -- The primary intended use case is to allow using 'IntervalSet' -- in maps and sets that require ordering. - Typeable + , Typeable ) type role IntervalMap nominal representational diff --git a/src/Data/IntervalSet.hs b/src/Data/IntervalSet.hs index 1092634..acddc7a 100644 --- a/src/Data/IntervalSet.hs +++ b/src/Data/IntervalSet.hs @@ -85,12 +85,12 @@ import qualified GHC.Exts as GHCExts -- Any connected intervals are merged together, and empty intervals are ignored. newtype IntervalSet r = IntervalSet (Map (Extended r) (Interval r)) deriving - ( Eq, - Ord, + ( Eq + , Ord -- ^ Note that this Ord is derived and not semantically meaningful. -- The primary intended use case is to allow using 'IntervalSet' -- in maps and sets that require ordering. - Typeable + , Typeable ) type role IntervalSet nominal