Skip to content

Commit

Permalink
Have Eq, Ord, and Hashable instances of LHName ignore the Symbol of r…
Browse files Browse the repository at this point in the history
…esolved names
  • Loading branch information
facundominguez committed Nov 7, 2024
1 parent 6d4a518 commit 3bdd1ff
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions liquidhaskell-boot/src/Language/Haskell/Liquid/Types/Names.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,26 @@ data LHName
-- unresolved names.
LHNResolved !LHResolvedName !Symbol
| LHNUnresolved !LHNameSpace !Symbol
deriving (Data, Eq, Generic, Ord)
deriving (Data, Generic)

-- | An Eq instance that ignores the Symbol in resolved names
instance Eq LHName where
LHNResolved n0 _ == LHNResolved n1 _ = n0 == n1
LHNUnresolved ns0 s0 == LHNUnresolved ns1 s1 = ns0 == ns1 && s0 == s1
_ == _ = False

-- | An Ord instance that ignores the Symbol in resolved names
instance Ord LHName where
compare (LHNResolved n0 _) (LHNResolved n1 _) = compare n0 n1
compare (LHNUnresolved ns0 s0) (LHNUnresolved ns1 s1) =
compare (ns0, s0) (ns1, s1)
compare LHNResolved{} _ = LT
compare LHNUnresolved{} _ = GT

-- | A Hashable instance that ignores the Symbol in resolved names
instance Hashable LHName where
hashWithSalt s (LHNResolved n _) = hashWithSalt s n
hashWithSalt s (LHNUnresolved ns sym) = s `hashWithSalt` ns `hashWithSalt` sym

data LHNameSpace
= LHTcName
Expand Down Expand Up @@ -115,7 +134,6 @@ instance Hashable LHResolvedName where
hashWithSalt s (LHRLocal n) = s `hashWithSalt` (2::Int) `hashWithSalt` n
hashWithSalt s (LHRIndex w) = s `hashWithSalt` (3::Int) `hashWithSalt` w

instance Hashable LHName
instance Hashable LogicName where
hashWithSalt s (LogicName sym m) =
s `hashWithSalt` sym
Expand Down

0 comments on commit 3bdd1ff

Please sign in to comment.