@@ -73,6 +73,8 @@ import qualified Data.Binary as B
7373import Data.Binary hiding (get, put)
7474import Foreign.Storable (sizeOf)
7575
76+import Numeric.IEEE (IEEE (identicalIEEE))
77+
7678import Util.Pretty hiding (Str)
7779
7880data Option = TTypeInTType
@@ -708,7 +710,30 @@ data Const = I Int | BI Integer | Fl Double | Ch Char | Str String
708710 | AType ArithTy | StrType
709711 | WorldType | TheWorld
710712 | VoidType | Forgot
711− deriving (Eq, Ord, Data, Typeable)
713+ deriving (Ord, Data, Typeable)
714+
715+-- We need to compare Double using bit-pattern identity rather than
716+-- Haskell's Eq, which equates 0.0 and -0.0, leading to a
717+-- contradiction in the type theory. Bit-pattern identity will also
718+-- avoid similar problems for NaNs.
719+instance Eq Const where
720+ I i == I j = i == j
721+ BI i == BI j = i == j
722+ Fl i == Fl j = identicalIEEE i j
723+ Ch i == Ch j = i == j
724+ Str i == Str j = i == j
725+ B8 i == B8 j = i == j
726+ B16 i == B16 j = i == j
727+ B32 i == B32 j = i == j
728+ B64 i == B64 j = i == j
729+ AType i == AType j = i == j
730+ StrType == StrType = True
731+ WorldType == WorldType = True
732+ TheWorld == TheWorld = True
733+ VoidType == VoidType = True
734+ Forgot == Forgot = True
735+ _ == _ = False
736+
712737{-!
713738deriving instance Binary Const
714739deriving instance NFData Const