From 7ff78c251654969f9973c087bec3ae98d5e5b606 Mon Sep 17 00:00:00 2001 From: simonpj Date: Mon, 18 Nov 2002 14:22:01 +0000 Subject: [PATCH] [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 --- ghc/compiler/typecheck/TcMType.lhs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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) -- 1.7.10.4