Skip to content

Commit 15b5b05

Browse files
authored
Merge pull request #9387 from haskell/ord-for-fields
Add instance Ord for Field, FieldLine, SectionArg and Name
2 parents 2fca50b + af0126c commit 15b5b05

File tree

1 file changed

+13
-0
lines changed
  • Cabal-syntax/src/Distribution/Fields

1 file changed

+13
-0
lines changed

Cabal-syntax/src/Distribution/Fields/Field.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{-# LANGUAGE DeriveFoldable #-}
33
{-# LANGUAGE DeriveFunctor #-}
44
{-# LANGUAGE DeriveTraversable #-}
5+
{-# LANGUAGE StandaloneDeriving #-}
56

67
-- | Cabal-like file AST types: 'Field', 'Section' etc
78
--
@@ -51,6 +52,9 @@ data Field ann
5152
| Section !(Name ann) [SectionArg ann] [Field ann]
5253
deriving (Eq, Show, Functor, Foldable, Traversable)
5354

55+
-- | @since 3.12.0.0
56+
deriving instance Ord ann => Ord (Field ann)
57+
5458
-- | Section of field name
5559
fieldName :: Field ann -> Name ann
5660
fieldName (Field n _) = n
@@ -73,6 +77,9 @@ fieldUniverse f@(Field _ _) = [f]
7377
data FieldLine ann = FieldLine !ann !ByteString
7478
deriving (Eq, Show, Functor, Foldable, Traversable)
7579

80+
-- | @since 3.12.0.0
81+
deriving instance Ord ann => Ord (FieldLine ann)
82+
7683
-- | @since 3.0.0.0
7784
fieldLineAnn :: FieldLine ann -> ann
7885
fieldLineAnn (FieldLine ann _) = ann
@@ -91,6 +98,9 @@ data SectionArg ann
9198
SecArgOther !ann !ByteString
9299
deriving (Eq, Show, Functor, Foldable, Traversable)
93100

101+
-- | @since 3.12.0.0
102+
deriving instance Ord ann => Ord (SectionArg ann)
103+
94104
-- | Extract annotation from 'SectionArg'.
95105
sectionArgAnn :: SectionArg ann -> ann
96106
sectionArgAnn (SecArgName ann _) = ann
@@ -109,6 +119,9 @@ type FieldName = ByteString
109119
data Name ann = Name !ann !FieldName
110120
deriving (Eq, Show, Functor, Foldable, Traversable)
111121

122+
-- | @since 3.12.0.0
123+
deriving instance Ord ann => Ord (Name ann)
124+
112125
mkName :: ann -> FieldName -> Name ann
113126
mkName ann bs = Name ann (B.map Char.toLower bs)
114127

0 commit comments

Comments
 (0)