Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ord instances for Interval, IntervalSet and IntervalMap #41

Merged
merged 2 commits into from
Sep 11, 2023
Merged
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
9 changes: 8 additions & 1 deletion src/Data/Interval/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/Data/IntervalMap/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion src/Data/IntervalSet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading