[project @ 2000-11-24 17:02:01 by simonpj]
[ghc-hetmet.git] / ghc / compiler / typecheck / TcDeriv.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[TcDeriv]{Deriving}
5
6 Handles @deriving@ clauses on @data@ declarations.
7
8 \begin{code}
9 module TcDeriv ( tcDeriving ) where
10
11 #include "HsVersions.h"
12
13 import HsSyn            ( HsBinds(..), MonoBinds(..), TyClDecl(..),
14                           collectLocatedMonoBinders )
15 import RdrHsSyn         ( RdrNameMonoBinds )
16 import RnHsSyn          ( RenamedHsBinds, RenamedMonoBinds, RenamedTyClDecl )
17 import CmdLineOpts      ( DynFlag(..), DynFlags )
18
19 import TcMonad
20 import TcEnv            ( TcEnv, tcSetInstEnv, newDFunName, InstInfo(..), pprInstInfo,
21                           tcLookupClass, tcLookupTyCon
22                         )
23 import TcGenDeriv       -- Deriv stuff
24 import InstEnv          ( InstEnv, simpleDFunClassTyCon, extendInstEnv )
25 import TcSimplify       ( tcSimplifyThetas )
26
27 import RnBinds          ( rnMethodBinds, rnTopMonoBinds )
28 import RnEnv            ( bindLocatedLocalsRn )
29 import RnMonad          ( renameDerivedCode, thenRn, mapRn, returnRn )
30 import HscTypes         ( DFunId, PersistentRenamerState )
31
32 import BasicTypes       ( Fixity )
33 import Class            ( classKey, Class )
34 import ErrUtils         ( dumpIfSet_dyn, Message )
35 import MkId             ( mkDictFunId )
36 import DataCon          ( dataConArgTys, isNullaryDataCon, isExistentialDataCon )
37 import PrelInfo         ( needsDataDeclCtxtClassKeys )
38 import Maybes           ( maybeToBool, catMaybes )
39 import Module           ( Module )
40 import Name             ( Name, getSrcLoc )
41 import RdrName          ( RdrName )
42
43 import TyCon            ( tyConTyVars, tyConDataCons,
44                           tyConTheta, maybeTyConSingleCon, isDataTyCon,
45                           isEnumerationTyCon, TyCon
46                         )
47 import Type             ( TauType, PredType(..), mkTyVarTys, mkTyConApp, isUnboxedType )
48 import Var              ( TyVar )
49 import PrelNames
50 import Util             ( zipWithEqual, sortLt )
51 import ListSetOps       ( removeDups,  assoc )
52 import Outputable
53 import List             ( nub )
54 \end{code}
55
56 %************************************************************************
57 %*                                                                      *
58 \subsection[TcDeriv-intro]{Introduction to how we do deriving}
59 %*                                                                      *
60 %************************************************************************
61
62 Consider
63
64         data T a b = C1 (Foo a) (Bar b)
65                    | C2 Int (T b a)
66                    | C3 (T a a)
67                    deriving (Eq)
68
69 [NOTE: See end of these comments for what to do with 
70         data (C a, D b) => T a b = ...
71 ]
72
73 We want to come up with an instance declaration of the form
74
75         instance (Ping a, Pong b, ...) => Eq (T a b) where
76                 x == y = ...
77
78 It is pretty easy, albeit tedious, to fill in the code "...".  The
79 trick is to figure out what the context for the instance decl is,
80 namely @Ping@, @Pong@ and friends.
81
82 Let's call the context reqd for the T instance of class C at types
83 (a,b, ...)  C (T a b).  Thus:
84
85         Eq (T a b) = (Ping a, Pong b, ...)
86
87 Now we can get a (recursive) equation from the @data@ decl:
88
89         Eq (T a b) = Eq (Foo a) u Eq (Bar b)    -- From C1
90                    u Eq (T b a) u Eq Int        -- From C2
91                    u Eq (T a a)                 -- From C3
92
93 Foo and Bar may have explicit instances for @Eq@, in which case we can
94 just substitute for them.  Alternatively, either or both may have
95 their @Eq@ instances given by @deriving@ clauses, in which case they
96 form part of the system of equations.
97
98 Now all we need do is simplify and solve the equations, iterating to
99 find the least fixpoint.  Notice that the order of the arguments can
100 switch around, as here in the recursive calls to T.
101
102 Let's suppose Eq (Foo a) = Eq a, and Eq (Bar b) = Ping b.
103
104 We start with:
105
106         Eq (T a b) = {}         -- The empty set
107
108 Next iteration:
109         Eq (T a b) = Eq (Foo a) u Eq (Bar b)    -- From C1
110                    u Eq (T b a) u Eq Int        -- From C2
111                    u Eq (T a a)                 -- From C3
112
113         After simplification:
114                    = Eq a u Ping b u {} u {} u {}
115                    = Eq a u Ping b
116
117 Next iteration:
118
119         Eq (T a b) = Eq (Foo a) u Eq (Bar b)    -- From C1
120                    u Eq (T b a) u Eq Int        -- From C2
121                    u Eq (T a a)                 -- From C3
122
123         After simplification:
124                    = Eq a u Ping b
125                    u (Eq b u Ping a)
126                    u (Eq a u Ping a)
127
128                    = Eq a u Ping b u Eq b u Ping a
129
130 The next iteration gives the same result, so this is the fixpoint.  We
131 need to make a canonical form of the RHS to ensure convergence.  We do
132 this by simplifying the RHS to a form in which
133
134         - the classes constrain only tyvars
135         - the list is sorted by tyvar (major key) and then class (minor key)
136         - no duplicates, of course
137
138 So, here are the synonyms for the ``equation'' structures:
139
140 \begin{code}
141 type DerivEqn = (Name, Class, TyCon, [TyVar], DerivRhs)
142                 -- The Name is the name for the DFun we'll build
143                 -- The tyvars bind all the variables in the RHS
144
145 type DerivRhs = [(Class, [TauType])]    -- Same as a ThetaType!
146                 --[PredType]   -- ... | Class Class [Type==TauType]
147
148 type DerivSoln = DerivRhs
149 \end{code}
150
151
152 A note about contexts on data decls
153 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
154 Consider
155
156         data (RealFloat a) => Complex a = !a :+ !a deriving( Read )
157
158 We will need an instance decl like:
159
160         instance (Read a, RealFloat a) => Read (Complex a) where
161           ...
162
163 The RealFloat in the context is because the read method for Complex is bound
164 to construct a Complex, and doing that requires that the argument type is
165 in RealFloat. 
166
167 But this ain't true for Show, Eq, Ord, etc, since they don't construct
168 a Complex; they only take them apart.
169
170 Our approach: identify the offending classes, and add the data type
171 context to the instance decl.  The "offending classes" are
172
173         Read, Enum?
174
175
176 %************************************************************************
177 %*                                                                      *
178 \subsection[TcDeriv-driver]{Top-level function for \tr{derivings}}
179 %*                                                                      *
180 %************************************************************************
181
182 \begin{code}
183 tcDeriving  :: PersistentRenamerState
184             -> Module                   -- name of module under scrutiny
185             -> InstEnv                  -- What we already know about instances
186             -> (Name -> Maybe Fixity)   -- used in deriving Show and Read
187             -> [RenamedTyClDecl]        -- All type constructors
188             -> TcM ([InstInfo],         -- The generated "instance decls".
189                     RenamedHsBinds)     -- Extra generated bindings
190
191 tcDeriving prs mod inst_env_in get_fixity tycl_decls
192   = recoverTc (returnTc ([], EmptyBinds)) $
193
194         -- Fish the "deriving"-related information out of the TcEnv
195         -- and make the necessary "equations".
196     makeDerivEqns tycl_decls            `thenTc` \ eqns ->
197     if null eqns then
198         returnTc ([], EmptyBinds)
199     else
200
201         -- Take the equation list and solve it, to deliver a list of
202         -- solutions, a.k.a. the contexts for the instance decls
203         -- required for the corresponding equations.
204     solveDerivEqns inst_env_in eqns             `thenTc` \ new_dfuns ->
205
206         -- Now augment the InstInfos, adding in the rather boring
207         -- actual-code-to-do-the-methods binds.  We may also need to
208         -- generate extra not-one-inst-decl-specific binds, notably
209         -- "con2tag" and/or "tag2con" functions.  We do these
210         -- separately.
211
212     gen_taggery_Names new_dfuns                 `thenTc` \ nm_alist_etc ->
213
214     tcGetEnv                                    `thenNF_Tc` \ env ->
215     getDOptsTc                                  `thenTc` \ dflags ->
216     let
217         extra_mbind_list = map gen_tag_n_con_monobind nm_alist_etc
218         extra_mbinds     = foldr AndMonoBinds EmptyMonoBinds extra_mbind_list
219         method_binds_s   = map (gen_bind get_fixity) new_dfuns
220         mbinders         = collectLocatedMonoBinders extra_mbinds
221         
222         -- Rename to get RenamedBinds.
223         -- The only tricky bit is that the extra_binds must scope over the
224         -- method bindings for the instances.
225         (rn_method_binds_s, rn_extra_binds)
226                 = renameDerivedCode dflags mod prs (
227                         bindLocatedLocalsRn (ptext (SLIT("deriving"))) mbinders $ \ _ ->
228                         rnTopMonoBinds extra_mbinds []          `thenRn` \ (rn_extra_binds, _) ->
229                         mapRn rn_meths method_binds_s           `thenRn` \ rn_method_binds_s ->
230                         returnRn (rn_method_binds_s, rn_extra_binds)
231                   )
232
233         new_inst_infos = zipWith gen_inst_info new_dfuns rn_method_binds_s
234     in
235
236     ioToTc (dumpIfSet_dyn dflags Opt_D_dump_deriv "Derived instances" 
237               (ddump_deriving new_inst_infos rn_extra_binds))   `thenTc_`
238
239     returnTc (new_inst_infos, rn_extra_binds)
240   where
241     ddump_deriving :: [InstInfo] -> RenamedHsBinds -> SDoc
242     ddump_deriving inst_infos extra_binds
243       = vcat (map pprInstInfo inst_infos) $$ ppr extra_binds
244       where
245
246         -- Make a Real dfun instead of the dummy one we have so far
247     gen_inst_info :: DFunId -> RenamedMonoBinds -> InstInfo
248     gen_inst_info dfun binds
249       = InstInfo { iLocal = True,  iDFunId = dfun, 
250                    iBinds = binds, iPrags = [] }
251
252     rn_meths meths = rnMethodBinds [] meths `thenRn` \ (meths', _) -> returnRn meths'
253         -- Ignore the free vars returned
254 \end{code}
255
256
257 %************************************************************************
258 %*                                                                      *
259 \subsection[TcDeriv-eqns]{Forming the equations}
260 %*                                                                      *
261 %************************************************************************
262
263 @makeDerivEqns@ fishes around to find the info about needed derived
264 instances.  Complicating factors:
265 \begin{itemize}
266 \item
267 We can only derive @Enum@ if the data type is an enumeration
268 type (all nullary data constructors).
269
270 \item
271 We can only derive @Ix@ if the data type is an enumeration {\em
272 or} has just one data constructor (e.g., tuples).
273 \end{itemize}
274
275 [See Appendix~E in the Haskell~1.2 report.] This code here deals w/
276 all those.
277
278 \begin{code}
279 makeDerivEqns :: [RenamedTyClDecl] -> TcM [DerivEqn]
280
281 makeDerivEqns tycl_decls
282   = mapTc mk_eqn derive_these           `thenTc` \ maybe_eqns ->
283     returnTc (catMaybes maybe_eqns)
284   where
285     ------------------------------------------------------------------
286     derive_these :: [(Name, Name)]
287         -- Find the (Class,TyCon) pairs that must be `derived'
288         -- NB: only source-language decls have deriving, no imported ones do
289     derive_these = [ (clas,tycon) 
290                    | TyData {tcdName = tycon, tcdDerivs = Just classes} <- tycl_decls,
291                      clas <- nub classes ]
292
293     ------------------------------------------------------------------
294     mk_eqn :: (Name, Name) -> NF_TcM (Maybe DerivEqn)
295         -- we swizzle the tyvars and datacons out of the tycon
296         -- to make the rest of the equation
297
298     mk_eqn (clas_name, tycon_name)
299       = tcLookupClass clas_name                                 `thenNF_Tc` \ clas ->
300         tcLookupTyCon tycon_name                                `thenNF_Tc` \ tycon ->
301         let
302             clas_key  = classKey clas
303             tyvars    = tyConTyVars tycon
304             tyvar_tys = mkTyVarTys tyvars
305             ty        = mkTyConApp tycon tyvar_tys
306             data_cons = tyConDataCons tycon
307             locn      = getSrcLoc tycon
308             constraints = extra_constraints ++ concat (map mk_constraints data_cons)
309
310             -- "extra_constraints": see notes above about contexts on data decls
311             extra_constraints
312               | offensive_class = tyConTheta tycon
313               | otherwise       = []
314
315             offensive_class = clas_key `elem` needsDataDeclCtxtClassKeys
316     
317             mk_constraints data_con
318                = [ (clas, [arg_ty])
319                  | arg_ty <- dataConArgTys data_con tyvar_tys,
320                    not (isUnboxedType arg_ty)   -- No constraints for unboxed types?
321                  ]
322         in
323         case chk_out clas tycon of
324            Just err ->  addErrTc err                            `thenNF_Tc_` 
325                         returnNF_Tc Nothing
326            Nothing  ->  newDFunName clas [ty] locn `thenNF_Tc` \ dfun_name ->
327                         returnNF_Tc (Just (dfun_name, clas, tycon, tyvars, constraints))
328
329
330
331     ------------------------------------------------------------------
332     chk_out :: Class -> TyCon -> Maybe Message
333     chk_out clas tycon
334         | clas `hasKey` enumClassKey    && not is_enumeration         = bog_out nullary_why
335         | clas `hasKey` boundedClassKey && not is_enumeration_or_single = bog_out single_nullary_why
336         | clas `hasKey` ixClassKey      && not is_enumeration_or_single = bog_out single_nullary_why
337         | any isExistentialDataCon (tyConDataCons tycon)              = Just (existentialErr clas tycon)
338         | otherwise                                                   = Nothing
339         where
340             is_enumeration = isEnumerationTyCon tycon
341             is_single_con  = maybeToBool (maybeTyConSingleCon tycon)
342             is_enumeration_or_single = is_enumeration || is_single_con
343
344             single_nullary_why = SLIT("one constructor data type or type with all nullary constructors expected")
345             nullary_why        = SLIT("data type with all nullary constructors expected")
346
347             bog_out why = Just (derivingThingErr clas tycon why)
348 \end{code}
349
350 %************************************************************************
351 %*                                                                      *
352 \subsection[TcDeriv-fixpoint]{Finding the fixed point of \tr{deriving} equations}
353 %*                                                                      *
354 %************************************************************************
355
356 A ``solution'' (to one of the equations) is a list of (k,TyVarTy tv)
357 terms, which is the final correct RHS for the corresponding original
358 equation.
359 \begin{itemize}
360 \item
361 Each (k,TyVarTy tv) in a solution constrains only a type
362 variable, tv.
363
364 \item
365 The (k,TyVarTy tv) pairs in a solution are canonically
366 ordered by sorting on type varible, tv, (major key) and then class, k,
367 (minor key)
368 \end{itemize}
369
370 \begin{code}
371 solveDerivEqns :: InstEnv
372                -> [DerivEqn]
373                -> TcM [DFunId]  -- Solns in same order as eqns.
374                                 -- This bunch is Absolutely minimal...
375
376 solveDerivEqns inst_env_in orig_eqns
377   = iterateDeriv initial_solutions
378   where
379         -- The initial solutions for the equations claim that each
380         -- instance has an empty context; this solution is certainly
381         -- in canonical form.
382     initial_solutions :: [DerivSoln]
383     initial_solutions = [ [] | _ <- orig_eqns ]
384
385     ------------------------------------------------------------------
386         -- iterateDeriv calculates the next batch of solutions,
387         -- compares it with the current one; finishes if they are the
388         -- same, otherwise recurses with the new solutions.
389         -- It fails if any iteration fails
390     iterateDeriv :: [DerivSoln] ->TcM [DFunId]
391     iterateDeriv current_solns
392       = checkNoErrsTc (iterateOnce current_solns)
393                                                 `thenTc` \ (new_dfuns, new_solns) ->
394         if (current_solns == new_solns) then
395             returnTc new_dfuns
396         else
397             iterateDeriv new_solns
398
399     ------------------------------------------------------------------
400     iterateOnce current_solns
401       =     -- Extend the inst info from the explicit instance decls
402             -- with the current set of solutions, giving a
403         getDOptsTc                              `thenTc` \ dflags ->
404         let (new_dfuns, inst_env) =
405                 add_solns dflags inst_env_in orig_eqns current_solns
406         in
407             -- Simplify each RHS
408         tcSetInstEnv inst_env (
409           listTc [ tcAddErrCtxt (derivCtxt tc) $
410                    tcSimplifyThetas deriv_rhs
411                  | (_, _,tc,_,deriv_rhs) <- orig_eqns ]  
412         )                                       `thenTc` \ next_solns ->
413
414             -- Canonicalise the solutions, so they compare nicely
415         let canonicalised_next_solns = [ sortLt (<) next_soln | next_soln <- next_solns ]
416         in
417         returnTc (new_dfuns, canonicalised_next_solns)
418 \end{code}
419
420 \begin{code}
421 add_solns :: DynFlags
422           -> InstEnv                            -- The global, non-derived ones
423           -> [DerivEqn] -> [DerivSoln]
424           -> ([DFunId], InstEnv)
425     -- the eqns and solns move "in lockstep"; we have the eqns
426     -- because we need the LHS info for addClassInstance.
427
428 add_solns dflags inst_env_in eqns solns
429   = (new_dfuns, inst_env)
430     where
431       new_dfuns     = zipWithEqual "add_solns" mk_deriv_dfun eqns solns
432       (inst_env, _) = extendInstEnv dflags inst_env_in new_dfuns
433         -- Ignore the errors about duplicate instances.
434         -- We don't want repeated error messages
435         -- They'll appear later, when we do the top-level extendInstEnvs
436
437       mk_deriv_dfun (dfun_name, clas, tycon, tyvars, _) theta
438         = mkDictFunId dfun_name clas tyvars [mkTyConApp tycon (mkTyVarTys tyvars)] 
439                       (map pair2PredType theta)
440
441       pair2PredType (clas, tautypes) = Class clas tautypes
442 \end{code}
443
444 %************************************************************************
445 %*                                                                      *
446 \subsection[TcDeriv-normal-binds]{Bindings for the various classes}
447 %*                                                                      *
448 %************************************************************************
449
450 After all the trouble to figure out the required context for the
451 derived instance declarations, all that's left is to chug along to
452 produce them.  They will then be shoved into @tcInstDecls2@, which
453 will do all its usual business.
454
455 There are lots of possibilities for code to generate.  Here are
456 various general remarks.
457
458 PRINCIPLES:
459 \begin{itemize}
460 \item
461 We want derived instances of @Eq@ and @Ord@ (both v common) to be
462 ``you-couldn't-do-better-by-hand'' efficient.
463
464 \item
465 Deriving @Show@---also pretty common--- should also be reasonable good code.
466
467 \item
468 Deriving for the other classes isn't that common or that big a deal.
469 \end{itemize}
470
471 PRAGMATICS:
472
473 \begin{itemize}
474 \item
475 Deriving @Ord@ is done mostly with the 1.3 @compare@ method.
476
477 \item
478 Deriving @Eq@ also uses @compare@, if we're deriving @Ord@, too.
479
480 \item
481 We {\em normally} generate code only for the non-defaulted methods;
482 there are some exceptions for @Eq@ and (especially) @Ord@...
483
484 \item
485 Sometimes we use a @_con2tag_<tycon>@ function, which returns a data
486 constructor's numeric (@Int#@) tag.  These are generated by
487 @gen_tag_n_con_binds@, and the heuristic for deciding if one of
488 these is around is given by @hasCon2TagFun@.
489
490 The examples under the different sections below will make this
491 clearer.
492
493 \item
494 Much less often (really just for deriving @Ix@), we use a
495 @_tag2con_<tycon>@ function.  See the examples.
496
497 \item
498 We use the renamer!!!  Reason: we're supposed to be
499 producing @RenamedMonoBinds@ for the methods, but that means
500 producing correctly-uniquified code on the fly.  This is entirely
501 possible (the @TcM@ monad has a @UniqueSupply@), but it is painful.
502 So, instead, we produce @RdrNameMonoBinds@ then heave 'em through
503 the renamer.  What a great hack!
504 \end{itemize}
505
506 \begin{code}
507 -- Generate the method bindings for the required instance
508 -- (paired with class name, as we need that when generating dict
509 --  names.)
510 gen_bind :: (Name -> Maybe Fixity) -> DFunId -> RdrNameMonoBinds
511 gen_bind get_fixity dfun
512   | clas `hasKey` showClassKey   = gen_Show_binds get_fixity tycon
513   | clas `hasKey` readClassKey   = gen_Read_binds get_fixity tycon
514   | otherwise
515   = assoc "gen_bind:bad derived class"
516            [(eqClassKey,      gen_Eq_binds)
517            ,(ordClassKey,     gen_Ord_binds)
518            ,(enumClassKey,    gen_Enum_binds)
519            ,(boundedClassKey, gen_Bounded_binds)
520            ,(ixClassKey,      gen_Ix_binds)
521            ]
522            (classKey clas)
523            tycon
524   where
525     (clas, tycon) = simpleDFunClassTyCon dfun
526 \end{code}
527
528
529 %************************************************************************
530 %*                                                                      *
531 \subsection[TcDeriv-taggery-Names]{What con2tag/tag2con functions are available?}
532 %*                                                                      *
533 %************************************************************************
534
535
536 data Foo ... = ...
537
538 con2tag_Foo :: Foo ... -> Int#
539 tag2con_Foo :: Int -> Foo ...   -- easier if Int, not Int#
540 maxtag_Foo  :: Int              -- ditto (NB: not unboxed)
541
542
543 We have a @con2tag@ function for a tycon if:
544 \begin{itemize}
545 \item
546 We're deriving @Eq@ and the tycon has nullary data constructors.
547
548 \item
549 Or: we're deriving @Ord@ (unless single-constructor), @Enum@, @Ix@
550 (enum type only????)
551 \end{itemize}
552
553 We have a @tag2con@ function for a tycon if:
554 \begin{itemize}
555 \item
556 We're deriving @Enum@, or @Ix@ (enum type only???)
557 \end{itemize}
558
559 If we have a @tag2con@ function, we also generate a @maxtag@ constant.
560
561 \begin{code}
562 gen_taggery_Names :: [DFunId]
563                   -> TcM [(RdrName,     -- for an assoc list
564                            TyCon,       -- related tycon
565                            TagThingWanted)]
566
567 gen_taggery_Names dfuns
568   = foldlTc do_con2tag []           tycons_of_interest `thenTc` \ names_so_far ->
569     foldlTc do_tag2con names_so_far tycons_of_interest
570   where
571     all_CTs = map simpleDFunClassTyCon dfuns
572     all_tycons              = map snd all_CTs
573     (tycons_of_interest, _) = removeDups compare all_tycons
574     
575     do_con2tag acc_Names tycon
576       | isDataTyCon tycon &&
577         ((we_are_deriving eqClassKey tycon
578             && any isNullaryDataCon (tyConDataCons tycon))
579          || (we_are_deriving ordClassKey  tycon
580             && not (maybeToBool (maybeTyConSingleCon tycon)))
581          || (we_are_deriving enumClassKey tycon)
582          || (we_are_deriving ixClassKey   tycon))
583         
584       = returnTc ((con2tag_RDR tycon, tycon, GenCon2Tag)
585                    : acc_Names)
586       | otherwise
587       = returnTc acc_Names
588
589     do_tag2con acc_Names tycon
590       | isDataTyCon tycon &&
591          (we_are_deriving enumClassKey tycon ||
592           we_are_deriving ixClassKey   tycon
593           && isEnumerationTyCon tycon)
594       = returnTc ( (tag2con_RDR tycon, tycon, GenTag2Con)
595                  : (maxtag_RDR  tycon, tycon, GenMaxTag)
596                  : acc_Names)
597       | otherwise
598       = returnTc acc_Names
599
600     we_are_deriving clas_key tycon
601       = is_in_eqns clas_key tycon all_CTs
602       where
603         is_in_eqns clas_key tycon [] = False
604         is_in_eqns clas_key tycon ((c,t):cts)
605           =  (clas_key == classKey c && tycon == t)
606           || is_in_eqns clas_key tycon cts
607 \end{code}
608
609 \begin{code}
610 derivingThingErr :: Class -> TyCon -> FAST_STRING -> Message
611
612 derivingThingErr clas tycon why
613   = sep [hsep [ptext SLIT("Can't make a derived instance of"), quotes (ppr clas)],
614          hsep [ptext SLIT("for the type"), quotes (ppr tycon)],
615          parens (ptext why)]
616
617 existentialErr clas tycon
618   = sep [ptext SLIT("Can't derive any instances for type") <+> quotes (ppr tycon),
619          ptext SLIT("because it has existentially-quantified constructor(s)")]
620
621 derivCtxt tycon
622   = ptext SLIT("When deriving classes for") <+> quotes (ppr tycon)
623 \end{code}