From: simonpj Date: Mon, 18 Nov 2002 14:22:01 +0000 (+0000) Subject: [project @ 2002-11-18 14:22:01 by simonpj] X-Git-Tag: Approx_11550_changesets_converted~1444 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=7ff78c251654969f9973c087bec3ae98d5e5b606;p=ghc-hetmet.git [project @ 2002-11-18 14:22:01 by simonpj] ---------------------------------- Ambiguity for implicit parameters --------------------------------- MERGE TO STABLE Implicit parameters do not cause amiguity. For example, this is OK: foo :: (?x :: [a]) => Int -> Int foo _ = length ?x Test is tcrun023.hs --- diff --git a/ghc/compiler/typecheck/TcMType.lhs b/ghc/compiler/typecheck/TcMType.lhs index daf2acf..0364a0e 100644 --- a/ghc/compiler/typecheck/TcMType.lhs +++ b/ghc/compiler/typecheck/TcMType.lhs @@ -50,7 +50,7 @@ import TypeRep ( Type(..), SourceType(..), TyNote(..), -- Friend; can see repr ) import TcType ( TcType, TcThetaType, TcTauType, TcPredType, TcTyVarSet, TcKind, TcTyVar, TyVarDetails(..), - tcEqType, tcCmpPred, + tcEqType, tcCmpPred, isClassPred, tcSplitPhiTy, tcSplitPredTy_maybe, tcSplitAppTy_maybe, tcSplitTyConApp_maybe, tcSplitForAllTys, tcIsTyVarTy, tcSplitSigmaTy, @@ -908,7 +908,14 @@ checkAmbiguity forall_tyvars theta tau_tyvars where complain pred = addErrTc (ambigErr pred) extended_tau_vars = grow theta tau_tyvars - is_ambig pred = any ambig_var (varSetElems (tyVarsOfPred pred)) + + -- Only a *class* predicate can give rise to ambiguity + -- An *implicit parameter* cannot. For example: + -- foo :: (?x :: [a]) => Int + -- foo = length ?x + -- is fine. The call site will suppply a particular 'x' + is_ambig pred = isClassPred pred && + any ambig_var (varSetElems (tyVarsOfPred pred)) ambig_var ct_var = (ct_var `elem` forall_tyvars) && not (ct_var `elemVarSet` extended_tau_vars)