Make comparison on equalities work right (ie look at the types)
authorsimonpj@microsoft.com <unknown>
Mon, 11 Aug 2008 10:40:11 +0000 (10:40 +0000)
committersimonpj@microsoft.com <unknown>
Mon, 11 Aug 2008 10:40:11 +0000 (10:40 +0000)
This patch makes
(s1~t1) == (s2~t2) iff s1==s2, t1==t2

The comparison and equality instances for Insts are really only
used in making the AvailEnv in TcSimplify, which equalities are
never put into, which is why we've gotten away with this for so long.

But I'm now using 'nub' in the error messages for equalities,
and in any case it makes sense to have the right equality!

compiler/typecheck/TcRnTypes.lhs

index 3e63827..ebf4101 100644 (file)
@@ -730,7 +730,8 @@ than with the Avails handling stuff in TcSimplify
 
 \begin{code}
 instance Ord Inst where
 
 \begin{code}
 instance Ord Inst where
-  compare = cmpInst
+   compare = cmpInst
+       -- Used *only* for AvailEnv in TcSimplify
 
 instance Eq Inst where
   (==) i1 i2 = case i1 `cmpInst` i2 of
 
 instance Eq Inst where
   (==) i1 i2 = case i1 `cmpInst` i2 of
@@ -761,11 +762,12 @@ cmpInst i1@(ImplicInst {}) i2@(ImplicInst {}) = tci_name i1 `compare` tci_name i
 cmpInst (ImplicInst {})    _                  = LT
 
        -- same for Equality constraints
 cmpInst (ImplicInst {})    _                  = LT
 
        -- same for Equality constraints
-cmpInst (EqInst {})    (Dict {})             = GT
-cmpInst (EqInst {})    (Method {})           = GT
-cmpInst (EqInst {})    (LitInst {})          = GT
-cmpInst (EqInst {})    (ImplicInst {})       = GT
-cmpInst i1@(EqInst {}) i2@(EqInst {})         = tci_name i1 `compare` tci_name i2
+cmpInst (EqInst {})    (Dict {})       = GT
+cmpInst (EqInst {})    (Method {})     = GT
+cmpInst (EqInst {})    (LitInst {})    = GT
+cmpInst (EqInst {})    (ImplicInst {}) = GT
+cmpInst i1@(EqInst {}) i2@(EqInst {})  = (tci_left  i1 `tcCmpType` tci_left  i2) `thenCmp`
+                                         (tci_right i1 `tcCmpType` tci_right i2)
 \end{code}
 
 
 \end{code}