Add assertion checks for mkCoVar/mkTyVar
[ghc-hetmet.git] / compiler / types / Type.lhs
index e872d6a..eeacb1a 100644 (file)
@@ -1,8 +1,9 @@
 %
+% (c) The University of Glasgow 2006
 % (c) The GRASP/AQUA Project, Glasgow University, 1998
 %
-\section[Type]{Type - public interface}
 
+Type - public interface
 
 \begin{code}
 module Type (
@@ -105,32 +106,23 @@ module Type (
 import TypeRep
 
 -- friends:
-import Var     ( Var, TyVar, tyVarKind, tyVarName, 
-                 setTyVarName, setTyVarKind, mkWildCoVar )
+import Var
 import VarEnv
 import VarSet
 
-import OccName ( tidyOccName )
-import Name    ( NamedThing(..), tidyNameOcc )
-import Class   ( Class, classTyCon )
-import PrelNames( openTypeKindTyConKey, unliftedTypeKindTyConKey, 
-                  ubxTupleKindTyConKey, argTypeKindTyConKey )
-import TyCon   ( TyCon, isRecursiveTyCon, isPrimTyCon,
-                 isUnboxedTupleTyCon, isUnLiftedTyCon,
-                 isFunTyCon, isNewTyCon, isClosedNewTyCon, isOpenTyCon,
-                 newTyConRep, newTyConRhs, 
-                 isAlgTyCon, tyConArity, isSuperKindTyCon,
-                 tcExpandTyCon_maybe, coreExpandTyCon_maybe,
-                 tyConKind, PrimRep(..), tyConPrimRep, tyConUnique,
-                  isCoercionTyCon_maybe, isCoercionTyCon
-               )
+import OccName
+import Name
+import Class
+import PrelNames
+import TyCon
 
 -- others
-import StaticFlags     ( opt_DictsStrict )
-import Util            ( mapAccumL, seqList, lengthIs, snocView, thenCmp, isEqual, all2 )
+import StaticFlags
+import Util
 import Outputable
-import UniqSet         ( sizeUniqSet )         -- Should come via VarSet
-import Maybe           ( isJust )
+import UniqSet
+
+import Data.Maybe      ( isJust )
 \end{code}
 
 
@@ -1028,9 +1020,13 @@ cmpPredX env (IParam n1 ty1) (IParam n2 ty2) = (n1 `compare` n2) `thenCmp` cmpTy
        -- This comparison is used exclusively (I think) for the
        -- finite map built in TcSimplify
 cmpPredX env (ClassP c1 tys1) (ClassP c2 tys2) = (c1 `compare` c2) `thenCmp` cmpTypesX env tys1 tys2
-cmpPredX env (IParam _ _)     (ClassP _ _)     = LT
-cmpPredX env (ClassP _ _)     (IParam _ _)     = GT
 cmpPredX env (EqPred ty1 ty2) (EqPred ty1' ty2') = (cmpTypeX env ty1 ty1') `thenCmp` (cmpTypeX env ty2 ty2')
+
+-- Constructor order: IParam < ClassP < EqPred
+cmpPredX env (IParam {})     _             = LT
+cmpPredX env (ClassP {})    (IParam {})     = GT
+cmpPredX env (ClassP {})    (EqPred {})     = LT
+cmpPredX env (EqPred {})    _              = GT
 \end{code}
 
 PredTypes are used as a FM key in TcSimplify, 
@@ -1293,7 +1289,7 @@ substTyVarBndr subst@(TvSubst in_scope env) old_var
        | is_co_var = setTyVarKind old_var (substTy subst kind)
        | otherwise = old_var
     kind = tyVarKind old_var
-    is_co_var = isCoercionKind kind
+    is_co_var = isCoVar old_var
 \end{code}
 
 ----------------------------------------------------
@@ -1430,7 +1426,7 @@ isKind k = isSuperKind (typeKind k)
 
 isSubKind :: Kind -> Kind -> Bool
 -- (k1 `isSubKind` k2) checks that k1 <: k2
-isSubKind (TyConApp kc1 []) (TyConApp kc2 []) = kc1 `isSubKindCon` kc1
+isSubKind (TyConApp kc1 []) (TyConApp kc2 []) = kc1 `isSubKindCon` kc2
 isSubKind (FunTy a1 r1) (FunTy a2 r2)        = (a2 `isSubKind` a1) && (r1 `isSubKind` r2)
 isSubKind (PredTy (EqPred ty1 ty2)) (PredTy (EqPred ty1' ty2')) 
   = ty1 `tcEqType` ty1' && ty2 `tcEqType` ty2'
@@ -1469,14 +1465,6 @@ defaultKind k
   | isSubArgTypeKind k  = liftedTypeKind
   | otherwise        = k
 
-isCoercionKind :: Kind -> Bool
--- All coercions are of form (ty1 :=: ty2)
--- This function is here rather than in Coercion, 
--- because it's used by substTy
-isCoercionKind k | Just k' <- kindView k = isCoercionKind k'
-isCoercionKind (PredTy (EqPred {}))     = True
-isCoercionKind other                    = False
-
 isEqPred :: PredType -> Bool
 isEqPred (EqPred _ _) = True
 isEqPred other       = False