+
+\begin{code}
+checkValidInstance :: [TyVar] -> ThetaType -> Class -> [TcType] -> TcM ()
+checkValidInstance tyvars theta clas inst_tys
+ = do { dflags <- getDOpts
+
+ ; checkValidTheta InstThetaCtxt theta
+ ; checkAmbiguity tyvars theta (tyVarsOfTypes inst_tys)
+
+ -- Check that instance inference will termainate
+ -- For Haskell 98, checkValidTheta has already done that
+ ; checkInstTermination dflags theta inst_tys
+
+ -- The Coverage Condition
+ ; checkTc (dopt Opt_AllowUndecidableInstances dflags ||
+ checkInstCoverage clas inst_tys)
+ (instTypeErr (pprClassPred clas inst_tys) msg)
+ }
+ where
+ msg = parens (ptext SLIT("the instance types do not agree with the functional dependencies of the class"))
+\end{code}
+