2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[TcClassDcl]{Typechecking class declarations}
7 module TcClassDcl ( tcClassDecl1, tcClassDecls2,
8 tcMethodBind, mkMethodBind, badMethodErr
11 #include "HsVersions.h"
13 import HsSyn ( TyClDecl(..), Sig(..), MonoBinds(..),
14 HsExpr(..), HsLit(..), Pat(WildPat),
15 mkSimpleMatch, andMonoBinds, andMonoBindList,
16 isClassOpSig, isPragSig,
19 import BasicTypes ( RecFlag(..), StrictnessMark(..) )
20 import RnHsSyn ( RenamedTyClDecl, RenamedSig,
21 RenamedClassOpSig, RenamedMonoBinds,
24 import RnEnv ( lookupSysName )
25 import TcHsSyn ( TcMonoBinds )
27 import Inst ( Inst, InstOrigin(..), instToId, newDicts, newMethodAtLoc )
28 import TcEnv ( TyThingDetails(..),
29 tcLookupClass, tcExtendTyVarEnv2,
32 import TcBinds ( tcMonoBinds )
33 import TcMonoType ( TcSigInfo(..), tcHsType, tcHsTheta, mkTcSig )
34 import TcSimplify ( tcSimplifyCheck )
35 import TcUnify ( checkSigTyVars, sigCtxt )
36 import TcMType ( tcInstTyVars )
37 import TcType ( Type, TyVarDetails(..), TcType, TcThetaType, TcTyVar,
38 mkTyVarTys, mkPredTys, mkClassPred, tcSplitSigmaTy, tcSplitFunTys,
39 tcIsTyVarTy, tcSplitTyConApp_maybe
42 import Generics ( mkGenericRhs )
43 import PrelInfo ( nO_METHOD_BINDING_ERROR_ID )
44 import Class ( classTyVars, classBigSig, classTyCon,
45 Class, ClassOpItem, DefMeth (..) )
46 import TyCon ( tyConGenInfo )
47 import MkId ( mkDictSelId, mkDataConId, mkDataConWrapId, mkDefaultMethodId )
48 import DataCon ( mkDataCon )
49 import Id ( Id, idType, idName, setIdLocalExported, setInlinePragma )
50 import Name ( Name, NamedThing(..) )
51 import NameEnv ( NameEnv, lookupNameEnv, emptyNameEnv, unitNameEnv, plusNameEnv )
52 import NameSet ( emptyNameSet, unitNameSet )
53 import OccName ( mkClassTyConOcc, mkClassDataConOcc, mkWorkerOcc, mkSuperDictSelOcc )
57 import UnicodeUtil ( stringToUtf8 )
58 import ErrUtils ( dumpIfSet )
59 import Util ( count, lengthIs )
60 import Maybes ( seqMaybe )
61 import Maybe ( isJust )
69 Every class implicitly declares a new data type, corresponding to dictionaries
70 of that class. So, for example:
72 class (D a) => C a where
74 op2 :: forall b. Ord b => a -> b -> b
76 would implicitly declare
78 data CDict a = CDict (D a)
80 (forall b. Ord b => a -> b -> b)
82 (We could use a record decl, but that means changing more of the existing apparatus.
85 For classes with just one superclass+method, we use a newtype decl instead:
88 op :: forallb. a -> b -> b
92 newtype CDict a = CDict (forall b. a -> b -> b)
94 Now DictTy in Type is just a form of type synomym:
95 DictTy c t = TyConTy CDict `AppTy` t
97 Death to "ExpandingDicts".
100 %************************************************************************
102 \subsection{Type checking}
104 %************************************************************************
108 tcClassDecl1 :: RenamedTyClDecl -> TcM (Name, TyThingDetails)
109 tcClassDecl1 (ClassDecl {tcdCtxt = context, tcdName = class_name,
110 tcdTyVars = tyvar_names, tcdFDs = fundeps,
111 tcdSigs = class_sigs, tcdMeths = def_methods,
113 = -- LOOK THINGS UP IN THE ENVIRONMENT
114 tcLookupClass class_name `thenM` \ clas ->
116 tyvars = classTyVars clas
117 op_sigs = filter isClassOpSig class_sigs
118 op_names = [n | ClassOpSig n _ _ _ <- op_sigs]
120 tcExtendTyVarEnv tyvars $
122 checkDefaultBinds clas op_names def_methods `thenM` \ mb_dm_env ->
125 -- The renamer has already checked that the context mentions
126 -- only the type variable of the class decl.
127 -- Context is already kind-checked
128 tcHsTheta context `thenM` \ sc_theta ->
130 -- CHECK THE CLASS SIGNATURES,
131 mappM (tcClassSig clas tyvars mb_dm_env) op_sigs `thenM` \ sig_stuff ->
133 -- MAKE THE CLASS DETAILS
134 lookupSysName class_name mkClassDataConOcc `thenM` \ datacon_name ->
135 lookupSysName datacon_name mkWorkerOcc `thenM` \ datacon_wkr_name ->
136 mapM (lookupSysName class_name . mkSuperDictSelOcc)
137 [1..length context] `thenM` \ sc_sel_names ->
138 -- We number off the superclass selectors, 1, 2, 3 etc so that we
139 -- can construct names for the selectors. Thus
140 -- class (C a, C b) => D a b where ...
141 -- gives superclass selectors
143 -- (We used to call them D_C, but now we can have two different
144 -- superclasses both called C!)
145 lookupSysName class_name mkClassTyConOcc `thenM` \ tycon_name ->
147 (op_tys, op_items) = unzip sig_stuff
148 sc_tys = mkPredTys sc_theta
149 dict_component_tys = sc_tys ++ op_tys
150 sc_sel_ids = [mkDictSelId sc_name clas | sc_name <- sc_sel_names]
152 dict_con = mkDataCon datacon_name
153 [NotMarkedStrict | _ <- dict_component_tys]
154 [{- No labelled fields -}]
157 [{-No existential tyvars-}] [{-Or context-}]
160 dict_con_id dict_wrap_id
162 dict_con_id = mkDataConId datacon_wkr_name dict_con
163 dict_wrap_id = mkDataConWrapId dict_con
165 returnM (class_name, ClassDetails sc_theta sc_sel_ids op_items dict_con tycon_name)
169 checkDefaultBinds :: Class -> [Name] -> Maybe RenamedMonoBinds
170 -> TcM (Maybe (NameEnv Bool))
171 -- The returned environment says
172 -- x not in env => no default method
173 -- x -> True => generic default method
174 -- x -> False => polymorphic default method
176 -- Check default bindings
177 -- a) must be for a class op for this class
178 -- b) must be all generic or all non-generic
179 -- and return a mapping from class-op to DefMeth info
181 -- But do all this only for source binds
183 checkDefaultBinds clas ops Nothing
186 checkDefaultBinds clas ops (Just mbs)
187 = go mbs `thenM` \ dm_env ->
188 returnM (Just dm_env)
190 go EmptyMonoBinds = returnM emptyNameEnv
192 go (AndMonoBinds b1 b2)
193 = go b1 `thenM` \ dm_info1 ->
194 go b2 `thenM` \ dm_info2 ->
195 returnM (dm_info1 `plusNameEnv` dm_info2)
197 go (FunMonoBind op _ matches loc)
200 -- Check that the op is from this class
201 checkTc (op `elem` ops) (badMethodErr clas op) `thenM_`
203 -- Check that all the defns ar generic, or none are
204 checkTc (all_generic || none_generic) (mixedGenericErr op) `thenM_`
206 returnM (unitNameEnv op all_generic)
208 n_generic = count (isJust . maybeGenericMatch) matches
209 none_generic = n_generic == 0
210 all_generic = matches `lengthIs` n_generic
215 tcClassSig :: Class -- ...ditto...
216 -> [TyVar] -- The class type variable, used for error check only
217 -> Maybe (NameEnv Bool) -- Info about default methods;
218 -- Nothing => imported class defn with no method binds
220 -> TcM (Type, -- Type of the method
221 ClassOpItem) -- Selector Id, default-method Id, True if explicit default binding
223 -- This warrants an explanation: we need to separate generic
224 -- default methods and default methods later on in the compiler
225 -- so we distinguish them in checkDefaultBinds, and pass this knowledge in the
226 -- Class.DefMeth data structure.
228 tcClassSig clas clas_tyvars maybe_dm_env
229 (ClassOpSig op_name sig_dm op_ty src_loc)
230 = addSrcLoc src_loc $
232 -- Check the type signature. NB that the envt *already has*
233 -- bindings for the type variables; see comments in TcTyAndClassDcls.
234 tcHsType op_ty `thenM` \ local_ty ->
237 theta = [mkClassPred clas (mkTyVarTys clas_tyvars)]
239 -- Build the selector id and default method id
240 sel_id = mkDictSelId op_name clas
241 DefMeth dm_name = sig_dm
243 dm_info = case maybe_dm_env of
245 Just dm_env -> mk_src_dm_info dm_env
247 mk_src_dm_info dm_env = case lookupNameEnv dm_env op_name of
249 Just True -> GenDefMeth
250 Just False -> DefMeth dm_name
252 returnM (local_ty, (sel_id, dm_info))
256 %************************************************************************
258 \subsection[Default methods]{Default methods}
260 %************************************************************************
262 The default methods for a class are each passed a dictionary for the
263 class, so that they get access to the other methods at the same type.
264 So, given the class decl
268 op2 :: Ord b => a -> b -> b -> b
271 op2 x y z = if (op1 x) && (y < z) then y else z
273 we get the default methods:
275 defm.Foo.op1 :: forall a. Foo a => a -> Bool
276 defm.Foo.op1 = /\a -> \dfoo -> \x -> True
278 defm.Foo.op2 :: forall a. Foo a => forall b. Ord b => a -> b -> b -> b
279 defm.Foo.op2 = /\ a -> \ dfoo -> /\ b -> \ dord -> \x y z ->
280 if (op1 a dfoo x) && (< b dord y z) then y else z
283 When we come across an instance decl, we may need to use the default
286 instance Foo Int where {}
290 const.Foo.Int.op1 :: Int -> Bool
291 const.Foo.Int.op1 = defm.Foo.op1 Int dfun.Foo.Int
293 const.Foo.Int.op2 :: forall b. Ord b => Int -> b -> b -> b
294 const.Foo.Int.op2 = defm.Foo.op2 Int dfun.Foo.Int
296 dfun.Foo.Int :: Foo Int
297 dfun.Foo.Int = (const.Foo.Int.op1, const.Foo.Int.op2)
299 Notice that, as with method selectors above, we assume that dictionary
300 application is curried, so there's no need to mention the Ord dictionary
301 in const.Foo.Int.op2 (or the type variable).
304 instance Foo a => Foo [a] where {}
306 dfun.Foo.List :: forall a. Foo a -> Foo [a]
308 = /\ a -> \ dfoo_a ->
310 op1 = defm.Foo.op1 [a] dfoo_list
311 op2 = defm.Foo.op2 [a] dfoo_list
312 dfoo_list = (op1, op2)
317 The function @tcClassDecls2@ just arranges to apply @tcClassDecl2@ to
318 each local class decl.
321 tcClassDecls2 :: [RenamedTyClDecl] -> TcM (TcMonoBinds, [Id])
325 (returnM (EmptyMonoBinds, []))
326 [tcClassDecl2 cls_decl | cls_decl@(ClassDecl {tcdMeths = Just _}) <- decls]
327 -- The 'Just' picks out source ClassDecls
329 combine tc1 tc2 = tc1 `thenM` \ (binds1, ids1) ->
330 tc2 `thenM` \ (binds2, ids2) ->
331 returnM (binds1 `AndMonoBinds` binds2,
335 @tcClassDecl2@ generates bindings for polymorphic default methods
336 (generic default methods have by now turned into instance declarations)
339 tcClassDecl2 :: RenamedTyClDecl -- The class declaration
340 -> TcM (TcMonoBinds, [Id])
342 tcClassDecl2 (ClassDecl {tcdName = class_name, tcdSigs = sigs,
343 tcdMeths = Just default_binds, tcdLoc = src_loc})
344 = -- The 'Just' picks out source ClassDecls
345 recoverM (returnM (EmptyMonoBinds, [])) $
347 tcLookupClass class_name `thenM` \ clas ->
349 -- We make a separate binding for each default method.
350 -- At one time I used a single AbsBinds for all of them, thus
351 -- AbsBind [d] [dm1, dm2, dm3] { dm1 = ...; dm2 = ...; dm3 = ... }
352 -- But that desugars into
353 -- ds = \d -> (..., ..., ...)
354 -- dm1 = \d -> case ds d of (a,b,c) -> a
355 -- And since ds is big, it doesn't get inlined, so we don't get good
356 -- default methods. Better to make separate AbsBinds for each
358 (tyvars, _, _, op_items) = classBigSig clas
359 prags = filter isPragSig sigs
360 tc_dm = tcDefMeth clas tyvars default_binds prags
362 mapAndUnzipM tc_dm op_items `thenM` \ (defm_binds, dm_ids_s) ->
364 returnM (andMonoBindList defm_binds, concat dm_ids_s)
367 tcDefMeth clas tyvars binds_in prags (_, NoDefMeth) = returnM (EmptyMonoBinds, [])
368 tcDefMeth clas tyvars binds_in prags (_, GenDefMeth) = returnM (EmptyMonoBinds, [])
369 -- Generate code for polymorphic default methods only
370 -- (Generic default methods have turned into instance decls by now.)
371 -- This is incompatible with Hugs, which expects a polymorphic
372 -- default method for every class op, regardless of whether or not
373 -- the programmer supplied an explicit default decl for the class.
374 -- (If necessary we can fix that, but we don't have a convenient Id to hand.)
376 tcDefMeth clas tyvars binds_in prags op_item@(sel_id, DefMeth dm_name)
377 = tcInstTyVars ClsTv tyvars `thenM` \ (clas_tyvars, inst_tys, _) ->
379 dm_ty = idType sel_id -- Same as dict selector!
380 -- The default method's type should really come from the
381 -- iface file, since it could be usage-generalised, but this
382 -- requires altering the mess of knots in TcModule and I'm
383 -- too scared to do that. Instead, I have disabled generalisation
384 -- of types of default methods (and dict funs) by annotating them
385 -- TyGenNever (in MkId). Ugh! KSW 1999-09.
387 theta = [mkClassPred clas inst_tys]
388 dm_id = mkDefaultMethodId dm_name dm_ty
389 local_dm_id = setIdLocalExported dm_id
390 -- Reason for setIdLocalExported: see notes with MkId.mkDictFunId
391 xtve = tyvars `zip` clas_tyvars
393 newDicts origin theta `thenM` \ [this_dict] ->
395 mkMethodBind origin clas inst_tys binds_in op_item `thenM` \ (dm_inst, meth_info) ->
396 getLIE (tcMethodBind xtve clas_tyvars theta
397 [this_dict] prags meth_info) `thenM` \ (defm_bind, insts_needed) ->
399 addErrCtxt (defltMethCtxt clas) $
403 (ptext SLIT("class") <+> ppr clas)
406 insts_needed `thenM` \ dict_binds ->
408 -- Simplification can do unification
409 checkSigTyVars clas_tyvars `thenM` \ clas_tyvars' ->
415 [(clas_tyvars', local_dm_id, instToId dm_inst)]
416 emptyNameSet -- No inlines (yet)
417 (dict_binds `andMonoBinds` defm_bind)
419 returnM (full_bind, [dm_id])
421 origin = ClassDeclOrigin
426 %************************************************************************
428 \subsection{Typechecking a method}
430 %************************************************************************
432 @tcMethodBind@ is used to type-check both default-method and
433 instance-decl method declarations. We must type-check methods one at a
434 time, because their signatures may have different contexts and
439 :: [(TyVar,TcTyVar)] -- Bindings for type environment
440 -> [TcTyVar] -- Instantiated type variables for the
441 -- enclosing class/instance decl.
442 -- They'll be signature tyvars, and we
443 -- want to check that they don't get bound
444 -- Always equal the range of the type envt
445 -> TcThetaType -- Available theta; it's just used for the error message
446 -> [Inst] -- Available from context, used to simplify constraints
447 -- from the method body
448 -> [RenamedSig] -- Pragmas (e.g. inline pragmas)
449 -> (Id, TcSigInfo, RenamedMonoBinds) -- Details of this method
452 tcMethodBind xtve inst_tyvars inst_theta avail_insts prags
453 (sel_id, meth_sig, meth_bind)
454 = -- Check the bindings; first adding inst_tyvars to the envt
455 -- so that we don't quantify over them in nested places
456 tcExtendTyVarEnv2 xtve (
457 addErrCtxt (methodCtxt sel_id) $
458 getLIE (tcMonoBinds meth_bind [meth_sig] NonRecursive)
459 ) `thenM` \ ((meth_bind, _, _), meth_lie) ->
461 -- Now do context reduction. We simplify wrt both the local tyvars
462 -- and the ones of the class/instance decl, so that there is
465 -- op :: Eq a => a -> b -> a
467 -- We do this for each method independently to localise error messages
470 TySigInfo meth_id meth_tvs meth_theta _ local_meth_id _ _ = meth_sig
472 addErrCtxtM (sigCtxt sel_id inst_tyvars inst_theta (idType meth_id)) $
473 newDicts SignatureOrigin meth_theta `thenM` \ meth_dicts ->
475 all_tyvars = meth_tvs ++ inst_tyvars
476 all_insts = avail_insts ++ meth_dicts
479 (ptext SLIT("class or instance method") <+> quotes (ppr sel_id))
480 all_tyvars all_insts meth_lie `thenM` \ lie_binds ->
482 checkSigTyVars all_tyvars `thenM` \ all_tyvars' ->
485 -- Attach inline pragmas as appropriate
486 (final_meth_id, inlines)
487 | (InlineSig inl _ phase _ : _) <- filter is_inline prags
488 = (meth_id `setInlinePragma` phase,
489 if inl then unitNameSet (idName meth_id) else emptyNameSet)
491 = (meth_id, emptyNameSet)
493 is_inline (InlineSig _ name _ _) = name == idName sel_id
494 is_inline other = False
496 meth_tvs' = take (length meth_tvs) all_tyvars'
497 poly_meth_bind = AbsBinds meth_tvs'
498 (map instToId meth_dicts)
499 [(meth_tvs', final_meth_id, local_meth_id)]
501 (lie_binds `andMonoBinds` meth_bind)
503 returnM poly_meth_bind
506 mkMethodBind :: InstOrigin
507 -> Class -> [TcType] -- Class and instance types
508 -> RenamedMonoBinds -- Method binding (pick the right one from in here)
510 -> TcM (Inst, -- Method inst
511 (Id, -- Global selector Id
512 TcSigInfo, -- Signature
513 RenamedMonoBinds)) -- Binding for the method
515 mkMethodBind origin clas inst_tys meth_binds (sel_id, dm_info)
516 = getInstLoc origin `thenM` \ inst_loc ->
517 newMethodAtLoc inst_loc sel_id inst_tys `thenM` \ meth_inst ->
518 -- Do not dump anything into the LIE
520 meth_id = instToId meth_inst
521 meth_name = idName meth_id
523 -- Figure out what method binding to use
524 -- If the user suppplied one, use it, else construct a default one
525 getSrcLocM `thenM` \ loc ->
526 (case find_bind (idName sel_id) meth_name meth_binds of
527 Just user_bind -> returnM user_bind
528 Nothing -> mkDefMethRhs origin clas inst_tys sel_id loc dm_info `thenM` \ rhs ->
529 returnM (FunMonoBind meth_name False -- Not infix decl
530 [mkSimpleMatch [] rhs placeHolderType loc] loc)
531 ) `thenM` \ meth_bind ->
533 mkTcSig meth_id loc `thenM` \ meth_sig ->
535 returnM (meth_inst, (sel_id, meth_sig, meth_bind))
538 -- The user didn't supply a method binding,
539 -- so we have to make up a default binding
540 -- The RHS of a default method depends on the default-method info
541 mkDefMethRhs origin clas inst_tys sel_id loc (DefMeth dm_name)
542 = -- An polymorphic default method
543 traceRn (text "mkDefMeth" <+> ppr dm_name) `thenM_`
544 returnM (HsVar dm_name)
546 mkDefMethRhs origin clas inst_tys sel_id loc NoDefMeth
547 = -- No default method
548 -- Warn only if -fwarn-missing-methods
549 doptM Opt_WarnMissingMethods `thenM` \ warn ->
550 warnTc (isInstDecl origin && warn)
551 (omittedMethodWarn sel_id) `thenM_`
554 error_rhs = HsLam (mkSimpleMatch wild_pats simple_rhs placeHolderType loc)
555 simple_rhs = HsApp (HsVar (getName nO_METHOD_BINDING_ERROR_ID))
556 (HsLit (HsStringPrim (mkFastString (stringToUtf8 error_msg))))
557 error_msg = showSDoc (hcat [ppr loc, text "|", ppr sel_id ])
559 -- When the type is of form t1 -> t2 -> t3
560 -- make a default method like (\ _ _ -> noMethBind "blah")
561 -- rather than simply (noMethBind "blah")
562 -- Reason: if t1 or t2 are higher-ranked types we get n
563 -- silly ambiguity messages.
564 -- Example: f :: (forall a. Eq a => a -> a) -> Int
566 -- Here, tcSub tries to force (error "urk") to have the right type,
567 -- thus: f = \(x::forall a. Eq a => a->a) -> error "urk" (x t)
568 -- where 't' is fresh ty var. This leads directly to "ambiguous t".
570 -- NB: technically this changes the meaning of the default-default
571 -- method slightly, because `seq` can see the lambdas. Oh well.
572 (_,_,tau1) = tcSplitSigmaTy (idType sel_id)
573 (_,_,tau2) = tcSplitSigmaTy tau1
574 -- Need two splits because the selector can have a type like
575 -- forall a. Foo a => forall b. Eq b => ...
576 (arg_tys, _) = tcSplitFunTys tau2
577 wild_pats = [WildPat placeHolderType | ty <- arg_tys]
579 mkDefMethRhs origin clas inst_tys sel_id loc GenDefMeth
580 = -- A generic default method
581 -- If the method is defined generically, we can only do the job if the
582 -- instance declaration is for a single-parameter type class with
583 -- a type constructor applied to type arguments in the instance decl
584 -- (checkTc, so False provokes the error)
585 ASSERT( isInstDecl origin ) -- We never get here from a class decl
587 checkTc (isJust maybe_tycon)
588 (badGenericInstance sel_id (notSimple inst_tys)) `thenM_`
589 checkTc (isJust (tyConGenInfo tycon))
590 (badGenericInstance sel_id (notGeneric tycon)) `thenM_`
592 ioToTcRn (dumpIfSet opt_PprStyle_Debug "Generic RHS" stuff) `thenM_`
595 rhs = mkGenericRhs sel_id clas_tyvar tycon
597 stuff = vcat [ppr clas <+> ppr inst_tys,
598 nest 4 (ppr sel_id <+> equals <+> ppr rhs)]
600 -- The tycon is only used in the generic case, and in that
601 -- case we require that the instance decl is for a single-parameter
602 -- type class with type variable arguments:
603 -- instance (...) => C (T a b)
604 clas_tyvar = head (classTyVars clas)
605 Just tycon = maybe_tycon
606 maybe_tycon = case inst_tys of
607 [ty] -> case tcSplitTyConApp_maybe ty of
608 Just (tycon, arg_tys) | all tcIsTyVarTy arg_tys -> Just tycon
612 isInstDecl InstanceDeclOrigin = True
613 isInstDecl ClassDeclOrigin = False
618 -- The renamer just puts the selector ID as the binder in the method binding
619 -- but we must use the method name; so we substitute it here. Crude but simple.
620 find_bind sel_name meth_name (FunMonoBind op_name fix matches loc)
621 | op_name == sel_name = Just (FunMonoBind meth_name fix matches loc)
622 find_bind sel_name meth_name (AndMonoBinds b1 b2)
623 = find_bind sel_name meth_name b1 `seqMaybe` find_bind sel_name meth_name b2
624 find_bind sel_name meth_name other = Nothing -- Default case
626 -- Find the prags for this method, and replace the
627 -- selector name with the method name
628 find_prags sel_name meth_name [] = []
629 find_prags sel_name meth_name (SpecSig name ty loc : prags)
630 | name == sel_name = SpecSig meth_name ty loc : find_prags sel_name meth_name prags
631 find_prags sel_name meth_name (InlineSig sense name phase loc : prags)
632 | name == sel_name = InlineSig sense meth_name phase loc : find_prags sel_name meth_name prags
633 find_prags sel_name meth_name (prag:prags) = find_prags sel_name meth_name prags
641 = ptext SLIT("When checking the default methods for class") <+> quotes (ppr clas)
644 = ptext SLIT("In the definition for method") <+> quotes (ppr sel_id)
647 = hsep [ptext SLIT("Class"), quotes (ppr clas),
648 ptext SLIT("does not have a method"), quotes (ppr op)]
650 omittedMethodWarn sel_id
651 = ptext SLIT("No explicit method nor default method for") <+> quotes (ppr sel_id)
653 badGenericInstance sel_id because
654 = sep [ptext SLIT("Can't derive generic code for") <+> quotes (ppr sel_id),
658 = vcat [ptext SLIT("because the instance type(s)"),
659 nest 2 (ppr inst_tys),
660 ptext SLIT("is not a simple type of form (T a b c)")]
663 = vcat [ptext SLIT("because the instance type constructor") <+> quotes (ppr tycon) <+>
664 ptext SLIT("was not compiled with -fgenerics")]
667 = ptext SLIT("Can't mix generic and non-generic equations for class method") <+> quotes (ppr op)