2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[TcClassDcl]{Typechecking class declarations}
7 module TcClassDcl ( kcClassDecl, tcClassDecl1, tcClassDecls2, mkImplicitClassBinds,
8 tcMethodBind, checkFromThisClass
11 #include "HsVersions.h"
13 import HsSyn ( HsDecl(..), TyClDecl(..), Sig(..), MonoBinds(..),
14 InPat(..), HsBinds(..), GRHSs(..),
15 HsExpr(..), HsLit(..), HsType(..), HsPred(..),
16 pprHsClassAssertion, unguardedRHS,
17 andMonoBinds, andMonoBindList, getTyVarName,
18 isClassDecl, isClassOpSig, isPragSig, collectMonoBinders
20 import HsPragmas ( ClassPragmas(..) )
21 import BasicTypes ( NewOrData(..), TopLevelFlag(..), RecFlag(..) )
22 import RnHsSyn ( RenamedTyClDecl, RenamedClassPragmas,
23 RenamedClassOpSig, RenamedMonoBinds,
24 RenamedContext, RenamedHsDecl, RenamedSig
26 import TcHsSyn ( TcMonoBinds, idsToMonoBinds )
28 import Inst ( Inst, InstOrigin(..), LIE, emptyLIE, plusLIE, plusLIEs, newDicts, newMethod )
29 import TcEnv ( TcId, ValueEnv, TcTyThing(..), tcAddImportedIdInfo,
30 tcLookupClass, tcLookupTy, tcExtendTyVarEnvForMeths, tcExtendGlobalTyVars,
33 import TcBinds ( tcBindWithSigs, tcSpecSigs )
34 import TcUnify ( unifyKinds )
36 import TcMonoType ( kcHsType, tcHsTopType, tcExtendTopTyVarScope,
37 tcContext, checkSigTyVars, sigCtxt, mkTcSig
39 import TcSimplify ( tcSimplifyAndCheck, bindInstsOfLocalFuns )
40 import TcType ( TcType, TcTyVar, tcInstTyVars, zonkTcTyVarBndr, tcGetTyVar )
41 import TcInstUtil ( classDataCon )
42 import PrelInfo ( nO_METHOD_BINDING_ERROR_ID )
43 import FieldLabel ( firstFieldLabelTag )
44 import Bag ( unionManyBags, bagToList )
45 import Class ( mkClass, classBigSig, classSelIds, Class, ClassOpItem )
46 import CmdLineOpts ( opt_GlasgowExts, opt_WarnMissingMethods )
47 import MkId ( mkDictSelId, mkDataConId, mkDataConWrapId, mkDefaultMethodId )
48 import DataCon ( mkDataCon, dataConId, dataConWrapId, notMarkedStrict )
49 import Id ( Id, setInlinePragma, idUnfolding, idType, idName )
50 import CoreUnfold ( unfoldingTemplate )
52 import Name ( Name, nameOccName, isLocallyDefined, NamedThing(..) )
53 import NameSet ( emptyNameSet )
55 import Type ( Type, ThetaType, ClassContext,
56 mkFunTy, mkTyVarTy, mkTyVarTys, mkDictTy,
57 mkSigmaTy, mkForAllTys, mkClassPred, classesOfPreds,
58 boxedTypeKind, mkArrowKind
60 import PprType ( {- instance Outputable Type -} )
61 import Var ( tyVarKind, TyVar )
62 import VarSet ( mkVarSet )
63 import TyCon ( mkAlgTyCon )
64 import Unique ( Unique, Uniquable(..) )
66 import Maybes ( seqMaybe )
67 import FiniteMap ( lookupWithDefaultFM )
74 Every class implicitly declares a new data type, corresponding to dictionaries
75 of that class. So, for example:
77 class (D a) => C a where
79 op2 :: forall b. Ord b => a -> b -> b
81 would implicitly declare
83 data CDict a = CDict (D a)
85 (forall b. Ord b => a -> b -> b)
87 (We could use a record decl, but that means changing more of the existing apparatus.
90 For classes with just one superclass+method, we use a newtype decl instead:
93 op :: forallb. a -> b -> b
97 newtype CDict a = CDict (forall b. a -> b -> b)
99 Now DictTy in Type is just a form of type synomym:
100 DictTy c t = TyConTy CDict `AppTy` t
102 Death to "ExpandingDicts".
105 %************************************************************************
107 \subsection{Kind checking}
109 %************************************************************************
112 kcClassDecl (ClassDecl context class_name
113 tyvar_names fundeps class_sigs def_methods pragmas
115 = -- CHECK ARITY 1 FOR HASKELL 1.4
116 checkTc (opt_GlasgowExts || length tyvar_names == 1)
117 (classArityErr class_name) `thenTc_`
119 -- Get the (mutable) class kind
120 tcLookupTy class_name `thenNF_Tc` \ (kind, _, _) ->
122 -- Make suitable tyvars and do kind checking
123 -- The net effect is to mutate the class kind
124 tcExtendTopTyVarScope kind tyvar_names $ \ _ _ ->
125 tcContext context `thenTc_`
126 mapTc kc_sig the_class_sigs `thenTc_`
130 the_class_sigs = filter isClassOpSig class_sigs
132 kc_sig (ClassOpSig _ _ _ op_ty loc) = tcAddSrcLoc loc (kcHsType op_ty)
136 %************************************************************************
138 \subsection{Type checking}
140 %************************************************************************
143 tcClassDecl1 rec_env rec_inst_mapper rec_vrcs
144 (ClassDecl context class_name
145 tyvar_names fundeps class_sigs def_methods pragmas
146 tycon_name datacon_name datacon_wkr_name sc_sel_names src_loc)
147 = -- LOOK THINGS UP IN THE ENVIRONMENT
148 tcLookupTy class_name `thenTc` \ (class_kind, _, AClass rec_class) ->
149 tcExtendTopTyVarScope class_kind tyvar_names $ \ tyvars _ ->
150 -- The class kind is by now immutable
153 -- traceTc (text "tcClassCtxt" <+> ppr class_name) `thenTc_`
154 tcClassContext class_name rec_class tyvars context sc_sel_names
155 `thenTc` \ (sc_theta, sc_tys, sc_sel_ids) ->
156 -- traceTc (text "tcClassCtxt done" <+> ppr class_name) `thenTc_`
158 -- CHECK THE FUNCTIONAL DEPENDENCIES,
159 tcFundeps fundeps `thenTc` \ fds ->
161 -- CHECK THE CLASS SIGNATURES,
162 mapTc (tcClassSig rec_env rec_class tyvars)
163 (filter isClassOpSig class_sigs)
164 `thenTc` \ sig_stuff ->
166 -- MAKE THE CLASS OBJECT ITSELF
168 (op_tys, op_items) = unzip sig_stuff
169 rec_class_inst_env = rec_inst_mapper rec_class
170 clas = mkClass class_name tyvars fds
171 sc_theta sc_sel_ids op_items
175 dict_component_tys = sc_tys ++ op_tys
176 new_or_data = case dict_component_tys of
180 dict_con = mkDataCon datacon_name
181 [notMarkedStrict | _ <- dict_component_tys]
182 [{- No labelled fields -}]
185 [{-No existential tyvars-}] [{-Or context-}]
187 tycon dict_con_id dict_wrap_id
189 dict_con_id = mkDataConId datacon_wkr_name dict_con
190 dict_wrap_id = mkDataConWrapId dict_con
192 argvrcs = lookupWithDefaultFM rec_vrcs (pprPanic "tcClassDecl1: argvrcs:" $
196 tycon = mkAlgTyCon tycon_name
201 [dict_con] -- Constructors
203 (Just clas) -- Yes! It's a dictionary
211 tcFundeps = mapTc tc_fundep
213 mapTc tc_fd_tyvar us `thenTc` \ us' ->
214 mapTc tc_fd_tyvar vs `thenTc` \ vs' ->
217 tcLookupTy v `thenTc` \(_, _, thing) ->
219 ATyVar tv -> returnTc tv
220 -- ZZ else should fail more gracefully
224 tcClassContext :: Name -> Class -> [TyVar]
225 -> RenamedContext -- class context
226 -> [Name] -- Names for superclass selectors
227 -> TcM s (ClassContext, -- the superclass context
228 [Type], -- types of the superclass dictionaries
229 [Id]) -- superclass selector Ids
231 tcClassContext class_name rec_class rec_tyvars context sc_sel_names
232 = -- Check the context.
233 -- The renamer has already checked that the context mentions
234 -- only the type variable of the class decl.
236 -- For std Haskell check that the context constrains only tyvars
237 (if opt_GlasgowExts then
240 mapTc check_constraint context
243 tcContext context `thenTc` \ sc_theta ->
246 sc_theta' = classesOfPreds sc_theta
247 sc_tys = [mkDictTy sc tys | (sc,tys) <- sc_theta']
248 sc_sel_ids = zipWithEqual "tcClassContext" mk_super_id sc_sel_names sc_tys
251 returnTc (sc_theta', sc_tys, sc_sel_ids)
254 rec_tyvar_tys = mkTyVarTys rec_tyvars
256 mk_super_id name dict_ty
257 = mkDictSelId name rec_class ty
259 ty = mkForAllTys rec_tyvars $
260 mkFunTy (mkDictTy rec_class rec_tyvar_tys) dict_ty
262 check_constraint (HsPClass c tys) = checkTc (all is_tyvar tys)
263 (superClassErr class_name (c, tys))
265 is_tyvar (MonoTyVar _) = True
266 is_tyvar other = False
269 tcClassSig :: ValueEnv -- Knot tying only!
270 -> Class -- ...ditto...
271 -> [TyVar] -- The class type variable, used for error check only
273 -> TcM s (Type, -- Type of the method
274 ClassOpItem) -- Selector Id, default-method Id, True if explicit default binding
277 tcClassSig rec_env rec_clas rec_clas_tyvars
278 (ClassOpSig op_name dm_name explicit_dm
280 = tcAddSrcLoc src_loc $
282 -- Check the type signature. NB that the envt *already has*
283 -- bindings for the type variables; see comments in TcTyAndClassDcls.
285 -- NB: Renamer checks that the class type variable is mentioned in local_ty,
286 -- and that it is not constrained by theta
287 -- traceTc (text "tcClassSig" <+> ppr op_name) `thenTc_`
288 tcHsTopType op_ty `thenTc` \ local_ty ->
290 global_ty = mkSigmaTy rec_clas_tyvars
291 [mkClassPred rec_clas (mkTyVarTys rec_clas_tyvars)]
294 -- Build the selector id and default method id
295 sel_id = mkDictSelId op_name rec_clas global_ty
296 dm_id = mkDefaultMethodId dm_name rec_clas global_ty
297 final_dm_id = tcAddImportedIdInfo rec_env dm_id
299 -- traceTc (text "tcClassSig done" <+> ppr op_name) `thenTc_`
300 returnTc (local_ty, (sel_id, final_dm_id, explicit_dm))
304 %************************************************************************
306 \subsection[ClassDcl-pass2]{Class decls pass 2: default methods}
308 %************************************************************************
310 The purpose of pass 2 is
313 to beat on the explicitly-provided default-method decls (if any),
314 using them to produce a complete set of default-method decls.
315 (Omitted ones elicit an error message.)
317 to produce a definition for the selector function for each method
318 and superclass dictionary.
321 Pass~2 only applies to locally-defined class declarations.
323 The function @tcClassDecls2@ just arranges to apply @tcClassDecl2@ to
324 each local class decl.
327 tcClassDecls2 :: [RenamedHsDecl]
328 -> NF_TcM s (LIE, TcMonoBinds)
332 (returnNF_Tc (emptyLIE, EmptyMonoBinds))
333 [tcClassDecl2 cls_decl | TyClD cls_decl <- decls, isClassDecl cls_decl]
335 combine tc1 tc2 = tc1 `thenNF_Tc` \ (lie1, binds1) ->
336 tc2 `thenNF_Tc` \ (lie2, binds2) ->
337 returnNF_Tc (lie1 `plusLIE` lie2,
338 binds1 `AndMonoBinds` binds2)
341 @tcClassDecl2@ is the business end of things.
344 tcClassDecl2 :: RenamedTyClDecl -- The class declaration
345 -> NF_TcM s (LIE, TcMonoBinds)
347 tcClassDecl2 (ClassDecl context class_name
348 tyvar_names _ class_sigs default_binds pragmas _ _ _ _ src_loc)
350 | not (isLocallyDefined class_name)
351 = returnNF_Tc (emptyLIE, EmptyMonoBinds)
353 | otherwise -- It is locally defined
354 = recoverNF_Tc (returnNF_Tc (emptyLIE, EmptyMonoBinds)) $
355 tcAddSrcLoc src_loc $
356 tcLookupClass class_name `thenNF_Tc` \ clas ->
357 tcDefaultMethodBinds clas default_binds class_sigs
361 mkImplicitClassBinds :: [Class] -> NF_TcM s ([Id], TcMonoBinds)
362 mkImplicitClassBinds classes
363 = returnNF_Tc (concat cls_ids_s, andMonoBindList binds_s)
364 -- The selector binds are already in the selector Id's unfoldings
366 (cls_ids_s, binds_s) = unzip (map mk_implicit classes)
368 mk_implicit clas = (all_cls_ids, binds)
370 dict_con = classDataCon clas
371 all_cls_ids = dataConId dict_con : cls_ids
372 cls_ids = dataConWrapId dict_con : classSelIds clas
374 -- The wrapper and selectors get bindings, the worker does not
375 binds | isLocallyDefined clas = idsToMonoBinds cls_ids
376 | otherwise = EmptyMonoBinds
379 %************************************************************************
381 \subsection[Default methods]{Default methods}
383 %************************************************************************
385 The default methods for a class are each passed a dictionary for the
386 class, so that they get access to the other methods at the same type.
387 So, given the class decl
391 op2 :: Ord b => a -> b -> b -> b
394 op2 x y z = if (op1 x) && (y < z) then y else z
396 we get the default methods:
398 defm.Foo.op1 :: forall a. Foo a => a -> Bool
399 defm.Foo.op1 = /\a -> \dfoo -> \x -> True
401 defm.Foo.op2 :: forall a. Foo a => forall b. Ord b => a -> b -> b -> b
402 defm.Foo.op2 = /\ a -> \ dfoo -> /\ b -> \ dord -> \x y z ->
403 if (op1 a dfoo x) && (< b dord y z) then y else z
406 When we come across an instance decl, we may need to use the default
409 instance Foo Int where {}
413 const.Foo.Int.op1 :: Int -> Bool
414 const.Foo.Int.op1 = defm.Foo.op1 Int dfun.Foo.Int
416 const.Foo.Int.op2 :: forall b. Ord b => Int -> b -> b -> b
417 const.Foo.Int.op2 = defm.Foo.op2 Int dfun.Foo.Int
419 dfun.Foo.Int :: Foo Int
420 dfun.Foo.Int = (const.Foo.Int.op1, const.Foo.Int.op2)
422 Notice that, as with method selectors above, we assume that dictionary
423 application is curried, so there's no need to mention the Ord dictionary
424 in const.Foo.Int.op2 (or the type variable).
427 instance Foo a => Foo [a] where {}
429 dfun.Foo.List :: forall a. Foo a -> Foo [a]
431 = /\ a -> \ dfoo_a ->
433 op1 = defm.Foo.op1 [a] dfoo_list
434 op2 = defm.Foo.op2 [a] dfoo_list
435 dfoo_list = (op1, op2)
445 -> TcM s (LIE, TcMonoBinds)
447 tcDefaultMethodBinds clas default_binds sigs
448 = -- Check that the default bindings come from this class
449 checkFromThisClass clas op_items default_binds `thenNF_Tc_`
451 -- Do each default method separately
452 -- For Hugs compatibility we make a default-method for every
453 -- class op, regardless of whether or not the programmer supplied an
454 -- explicit default decl for the class. GHC will actually never
455 -- call the default method for such operations, because it'll whip up
456 -- a more-informative default method at each instance decl.
457 mapAndUnzipTc tc_dm op_items `thenTc` \ (defm_binds, const_lies) ->
459 returnTc (plusLIEs const_lies, andMonoBindList defm_binds)
461 prags = filter isPragSig sigs
463 (tyvars, _, _, op_items) = classBigSig clas
465 origin = ClassDeclOrigin
467 -- We make a separate binding for each default method.
468 -- At one time I used a single AbsBinds for all of them, thus
469 -- AbsBind [d] [dm1, dm2, dm3] { dm1 = ...; dm2 = ...; dm3 = ... }
470 -- But that desugars into
471 -- ds = \d -> (..., ..., ...)
472 -- dm1 = \d -> case ds d of (a,b,c) -> a
473 -- And since ds is big, it doesn't get inlined, so we don't get good
474 -- default methods. Better to make separate AbsBinds for each
476 tc_dm op_item@(_, dm_id, _)
477 = tcInstTyVars tyvars `thenNF_Tc` \ (clas_tyvars, inst_tys, _) ->
479 theta = [(mkClassPred clas inst_tys)]
481 newDicts origin theta `thenNF_Tc` \ (this_dict, [this_dict_id]) ->
483 avail_insts = this_dict
485 tcExtendTyVarEnvForMeths tyvars clas_tyvars (
486 tcMethodBind clas origin clas_tyvars inst_tys theta
487 default_binds prags False
489 ) `thenTc` \ (defm_bind, insts_needed, (_, local_dm_id)) ->
491 tcAddErrCtxt (defltMethCtxt clas) $
493 -- tcMethodBind has checked that the class_tyvars havn't
494 -- been unified with each other or another type, but we must
495 -- still zonk them before passing them to tcSimplifyAndCheck
496 mapNF_Tc zonkTcTyVarBndr clas_tyvars `thenNF_Tc` \ clas_tyvars' ->
500 (ptext SLIT("class") <+> ppr clas)
501 (mkVarSet clas_tyvars')
503 insts_needed `thenTc` \ (const_lie, dict_binds) ->
509 [(clas_tyvars', dm_id, local_dm_id)]
510 emptyNameSet -- No inlines (yet)
511 (dict_binds `andMonoBinds` defm_bind)
513 returnTc (full_bind, const_lie)
517 checkFromThisClass :: Class -> [ClassOpItem] -> RenamedMonoBinds -> NF_TcM s ()
518 checkFromThisClass clas op_items mono_binds
519 = mapNF_Tc check_from_this_class bndrs `thenNF_Tc_`
522 check_from_this_class (bndr, loc)
523 | nameOccName bndr `elem` sel_names = returnNF_Tc ()
524 | otherwise = tcAddSrcLoc loc $
525 addErrTc (badMethodErr bndr clas)
526 sel_names = [getOccName sel_id | (sel_id,_,_) <- op_items]
527 bndrs = bagToList (collectMonoBinders mono_binds)
531 @tcMethodBind@ is used to type-check both default-method and
532 instance-decl method declarations. We must type-check methods one at a
533 time, because their signatures may have different contexts and
540 -> [TcTyVar] -- Instantiated type variables for the
541 -- enclosing class/instance decl.
542 -- They'll be signature tyvars, and we
543 -- want to check that they don't get bound
544 -> [TcType] -- Instance types
545 -> TcThetaType -- Available theta; this could be used to check
546 -- the method signature, but actually that's done by
547 -- the caller; here, it's just used for the error message
548 -> RenamedMonoBinds -- Method binding (pick the right one from in here)
549 -> [RenamedSig] -- Pramgas (just for this one)
550 -> Bool -- True <=> This method is from an instance declaration
551 -> ClassOpItem -- The method selector and default-method Id
552 -> TcM s (TcMonoBinds, LIE, (LIE, TcId))
554 tcMethodBind clas origin inst_tyvars inst_tys inst_theta
555 meth_binds prags is_inst_decl
556 (sel_id, dm_id, explicit_dm)
557 = tcGetSrcLoc `thenNF_Tc` \ loc ->
559 newMethod origin sel_id inst_tys `thenNF_Tc` \ meth@(_, meth_id) ->
560 mkTcSig meth_id loc `thenNF_Tc` \ sig_info ->
563 meth_name = idName meth_id
564 maybe_user_bind = find_bind meth_name meth_binds
566 no_user_bind = case maybe_user_bind of {Nothing -> True; other -> False}
568 meth_bind = case maybe_user_bind of
570 Nothing -> mk_default_bind meth_name loc
572 meth_prags = find_prags meth_name prags
575 -- Warn if no method binding, only if -fwarn-missing-methods
576 warnTc (is_inst_decl && opt_WarnMissingMethods && no_user_bind && not explicit_dm)
577 (omittedMethodWarn sel_id clas) `thenNF_Tc_`
579 -- Check the bindings; first add inst_tyvars to the envt
580 -- so that we don't quantify over them in nested places
581 -- The *caller* put the class/inst decl tyvars into the envt
582 tcExtendGlobalTyVars (mkVarSet inst_tyvars) (
583 tcAddErrCtxt (methodCtxt sel_id) $
584 tcBindWithSigs NotTopLevel meth_bind
585 [sig_info] meth_prags NonRecursive
586 ) `thenTc` \ (binds, insts, _) ->
589 tcExtendLocalValEnv [(meth_name, meth_id)] (
590 tcSpecSigs meth_prags
591 ) `thenTc` \ (prag_binds1, prag_lie) ->
593 -- The prag_lie for a SPECIALISE pragma will mention the function
594 -- itself, so we have to simplify them away right now lest they float
596 bindInstsOfLocalFuns prag_lie [meth_id] `thenTc` \ (prag_lie', prag_binds2) ->
599 -- Now check that the instance type variables
600 -- (or, in the case of a class decl, the class tyvars)
601 -- have not been unified with anything in the environment
602 tcAddErrCtxtM (sigCtxt sig_msg (mkSigmaTy inst_tyvars inst_theta (idType meth_id))) $
603 checkSigTyVars inst_tyvars `thenTc_`
605 returnTc (binds `AndMonoBinds` prag_binds1 `AndMonoBinds` prag_binds2,
606 insts `plusLIE` prag_lie',
609 sig_msg ty = sep [ptext SLIT("When checking the expected type for"),
610 nest 4 (ppr sel_name <+> dcolon <+> ppr ty)]
612 sel_name = idName sel_id
614 -- The renamer just puts the selector ID as the binder in the method binding
615 -- but we must use the method name; so we substitute it here. Crude but simple.
616 find_bind meth_name (FunMonoBind op_name fix matches loc)
617 | op_name == sel_name = Just (FunMonoBind meth_name fix matches loc)
618 find_bind meth_name (PatMonoBind (VarPatIn op_name) grhss loc)
619 | op_name == sel_name = Just (PatMonoBind (VarPatIn meth_name) grhss loc)
620 find_bind meth_name (AndMonoBinds b1 b2)
621 = find_bind meth_name b1 `seqMaybe` find_bind meth_name b2
622 find_bind meth_name other = Nothing -- Default case
625 -- Find the prags for this method, and replace the
626 -- selector name with the method name
627 find_prags meth_name [] = []
628 find_prags meth_name (SpecSig name ty loc : prags)
629 | name == sel_name = SpecSig meth_name ty loc : find_prags meth_name prags
630 find_prags meth_name (InlineSig name phase loc : prags)
631 | name == sel_name = InlineSig meth_name phase loc : find_prags meth_name prags
632 find_prags meth_name (NoInlineSig name phase loc : prags)
633 | name == sel_name = NoInlineSig meth_name phase loc : find_prags meth_name prags
634 find_prags meth_name (prag:prags) = find_prags meth_name prags
636 mk_default_bind local_meth_name loc
637 = PatMonoBind (VarPatIn local_meth_name)
638 (GRHSs (unguardedRHS (default_expr loc) loc) EmptyBinds Nothing)
642 | explicit_dm = HsVar (getName dm_id) -- There's a default method
643 | otherwise = error_expr loc -- No default method
645 error_expr loc = HsApp (HsVar (getName nO_METHOD_BINDING_ERROR_ID))
646 (HsLit (HsString (_PK_ (error_msg loc))))
648 error_msg loc = showSDoc (hcat [ppr loc, text "|", ppr sel_id ])
654 classArityErr class_name
655 = ptext SLIT("Too many parameters for class") <+> quotes (ppr class_name)
657 superClassErr class_name sc
658 = ptext SLIT("Illegal superclass constraint") <+> quotes (pprHsClassAssertion sc)
659 <+> ptext SLIT("in declaration for class") <+> quotes (ppr class_name)
661 defltMethCtxt class_name
662 = ptext SLIT("When checking the default methods for class") <+> quotes (ppr class_name)
665 = ptext SLIT("In the definition for method") <+> quotes (ppr sel_id)
667 badMethodErr bndr clas
668 = hsep [ptext SLIT("Class"), quotes (ppr clas),
669 ptext SLIT("does not have a method"), quotes (ppr bndr)]
671 omittedMethodWarn sel_id clas
672 = sep [ptext SLIT("No explicit method nor default method for") <+> quotes (ppr sel_id),
673 ptext SLIT("in an instance declaration for") <+> quotes (ppr clas)]