+ Evidence variables; range over constraints we can abstract over
+%* *
+%************************************************************************
+
+\begin{code}
+newEvVars :: TcThetaType -> TcM [EvVar]
+newEvVars theta = mapM newEvVar theta
+
+newWantedEvVar :: TcPredType -> TcM EvVar
+newWantedEvVar (EqPred ty1 ty2) = newWantedCoVar ty1 ty2
+newWantedEvVar (ClassP cls tys) = newDict cls tys
+newWantedEvVar (IParam ip ty) = newIP ip ty
+
+newWantedEvVars :: TcThetaType -> TcM [EvVar]
+newWantedEvVars theta = mapM newWantedEvVar theta
+
+newWantedCoVar :: TcType -> TcType -> TcM CoVar
+newWantedCoVar ty1 ty2 = newCoVar ty1 ty2
+
+-- We used to create a mutable co-var
+{-
+-- A wanted coercion variable is a MetaTyVar
+-- that can be filled in with its binding
+ = do { uniq <- newUnique
+ ; ref <- newMutVar Flexi
+ ; let name = mkSysTvName uniq (fsLit "c")
+ kind = mkPredTy (EqPred ty1 ty2)
+ ; return (mkTcTyVar name kind (MetaTv TauTv ref)) }
+-}
+
+--------------
+newEvVar :: TcPredType -> TcM EvVar
+-- Creates new *rigid* variables for predicates
+newEvVar (EqPred ty1 ty2) = newCoVar ty1 ty2
+newEvVar (ClassP cls tys) = newDict cls tys
+newEvVar (IParam ip ty) = newIP ip ty
+
+newCoVar :: TcType -> TcType -> TcM CoVar
+newCoVar ty1 ty2
+ = do { name <- newName (mkTyVarOccFS (fsLit "co"))
+ ; return (mkCoVar name (mkPredTy (EqPred ty1 ty2))) }
+
+newIP :: IPName Name -> TcType -> TcM IpId
+newIP ip ty
+ = do { name <- newName (getOccName (ipNameName ip))
+ ; return (mkLocalId name (mkPredTy (IParam ip ty))) }
+
+newDict :: Class -> [TcType] -> TcM DictId
+newDict cls tys
+ = do { name <- newName (mkDictOcc (getOccName cls))
+ ; return (mkLocalId name (mkPredTy (ClassP cls tys))) }
+
+newName :: OccName -> TcM Name
+newName occ
+ = do { uniq <- newUnique
+ ; loc <- getSrcSpanM
+ ; return (mkInternalName uniq occ loc) }
+
+-----------------
+newKindConstraint :: Type -> Kind -> TcM (CoVar, Type)
+-- Create a new wanted CoVar that constrains the type
+-- to have the specified kind
+newKindConstraint ty kind
+ = do { ty_k <- newFlexiTyVarTy kind
+ ; co_var <- newWantedCoVar ty ty_k
+ ; return (co_var, ty_k) }
+
+-----------------
+newSelfDict :: Class -> [TcType] -> TcM DictId
+-- Make a dictionary for "self". It behaves just like a normal DictId
+-- except that it responds True to isSelfDict
+-- This is used only to suppress confusing error reports
+newSelfDict cls tys
+ = do { uniq <- newUnique
+ ; let name = mkSystemName uniq selfDictOcc
+ ; return (mkLocalId name (mkPredTy (ClassP cls tys))) }
+
+selfDictOcc :: OccName
+selfDictOcc = mkVarOcc "self"
+
+isSelfDict :: EvVar -> Bool
+isSelfDict v = isSystemName (Var.varName v)
+ -- Notice that all *other* evidence variables get Internal Names
+\end{code}
+
+
+%************************************************************************
+%* *
+ SkolemTvs (immutable)