Skip to content

Commit

Permalink
Add an Eq/Ord instance for AnnotatedId.
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Z. Yang <[email protected]>
  • Loading branch information
ezyang committed Jan 3, 2018
1 parent d7a88c6 commit 52480b2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Cabal/Distribution/Types/AnnotatedId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ import Distribution.Types.ComponentName
-- | An 'AnnotatedId' is a 'ComponentId', 'UnitId', etc.
-- which is annotated with some other useful information
-- that is useful for printing to users, etc.
--
-- Invariant: if ann_id x == ann_id y, then ann_pid x == ann_pid y
-- and ann_cname x == ann_cname y
data AnnotatedId id = AnnotatedId {
ann_pid :: PackageId,
ann_cname :: ComponentName,
ann_id :: id
}
deriving (Show)

instance Eq id => Eq (AnnotatedId id) where
x == y = ann_id x == ann_id y

instance Ord id => Ord (AnnotatedId id) where
compare x y = compare (ann_id x) (ann_id y)

instance Package (AnnotatedId id) where
packageId = ann_pid

Expand Down

0 comments on commit 52480b2

Please sign in to comment.