Improve pretty-printing for IfaceConDecl
[ghc-hetmet.git] / compiler / iface / IfaceSyn.lhs
1 %
2 % (c) The University of Glasgow 2006
3 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1998
4 %
5
6 \begin{code}
7 module IfaceSyn (
8         module IfaceType,               -- Re-export all this
9
10         IfaceDecl(..), IfaceClassOp(..), IfaceConDecl(..), IfaceConDecls(..),
11         IfaceExpr(..), IfaceAlt, IfaceNote(..),
12         IfaceBinding(..), IfaceConAlt(..), IfaceIdInfo(..),
13         IfaceInfoItem(..), IfaceRule(..), IfaceInst(..), IfaceFamInst(..),
14
15         -- Misc
16         ifaceDeclSubBndrs, visibleIfConDecls,
17
18         -- Equality
19         GenIfaceEq(..), IfaceEq, (&&&), bool, eqListBy, eqMaybeBy,
20         eqIfDecl, eqIfInst, eqIfFamInst, eqIfRule, checkBootDecl,
21         
22         -- Pretty printing
23         pprIfaceExpr, pprIfaceDeclHead 
24     ) where
25
26 #include "HsVersions.h"
27
28 import CoreSyn
29 import IfaceType
30
31 import NewDemand
32 import Class
33 import UniqFM
34 import NameSet 
35 import Name
36 import CostCentre
37 import Literal
38 import ForeignCall
39 import BasicTypes
40 import Outputable
41 import FastString
42
43 import Data.List
44 import Data.Maybe
45
46 infixl 3 &&&
47 infix  4 `eqIfExt`, `eqIfIdInfo`, `eqIfType`
48 \end{code}
49
50
51 %************************************************************************
52 %*                                                                      *
53                 Data type declarations
54 %*                                                                      *
55 %************************************************************************
56
57 \begin{code}
58 data IfaceDecl 
59   = IfaceId { ifName   :: OccName,
60               ifType   :: IfaceType, 
61               ifIdInfo :: IfaceIdInfo }
62
63   | IfaceData { ifName       :: OccName,        -- Type constructor
64                 ifTyVars     :: [IfaceTvBndr],  -- Type variables
65                 ifCtxt       :: IfaceContext,   -- The "stupid theta"
66                 ifCons       :: IfaceConDecls,  -- Includes new/data info
67                 ifRec        :: RecFlag,        -- Recursive or not?
68                 ifGadtSyntax :: Bool,           -- True <=> declared using
69                                                 -- GADT syntax 
70                 ifGeneric    :: Bool,           -- True <=> generic converter
71                                                 --          functions available
72                                                 -- We need this for imported
73                                                 -- data decls, since the
74                                                 -- imported modules may have
75                                                 -- been compiled with
76                                                 -- different flags to the
77                                                 -- current compilation unit 
78                 ifFamInst    :: Maybe (IfaceTyCon, [IfaceType])
79                                                 -- Just <=> instance of family
80     }
81
82   | IfaceSyn  { ifName    :: OccName,           -- Type constructor
83                 ifTyVars  :: [IfaceTvBndr],     -- Type variables
84                 ifOpenSyn :: Bool,              -- Is an open family?
85                 ifSynRhs  :: IfaceType          -- Type for an ordinary
86                                                 -- synonym and kind for an
87                                                 -- open family
88     }
89
90   | IfaceClass { ifCtxt    :: IfaceContext,     -- Context...
91                  ifName    :: OccName,          -- Name of the class
92                  ifTyVars  :: [IfaceTvBndr],    -- Type variables
93                  ifFDs     :: [FunDep FastString], -- Functional dependencies
94                  ifATs     :: [IfaceDecl],      -- Associated type families
95                  ifSigs    :: [IfaceClassOp],   -- Method signatures
96                  ifRec     :: RecFlag           -- Is newtype/datatype associated with the class recursive?
97     }
98
99   | IfaceForeign { ifName :: OccName,           -- Needs expanding when we move
100                                                 -- beyond .NET
101                    ifExtName :: Maybe FastString }
102
103 data IfaceClassOp = IfaceClassOp OccName DefMeth IfaceType
104         -- Nothing    => no default method
105         -- Just False => ordinary polymorphic default method
106         -- Just True  => generic default method
107
108 data IfaceConDecls
109   = IfAbstractTyCon             -- No info
110   | IfOpenDataTyCon             -- Open data family
111   | IfOpenNewTyCon              -- Open newtype family
112   | IfDataTyCon [IfaceConDecl]  -- data type decls
113   | IfNewTyCon  IfaceConDecl    -- newtype decls
114
115 visibleIfConDecls :: IfaceConDecls -> [IfaceConDecl]
116 visibleIfConDecls IfAbstractTyCon  = []
117 visibleIfConDecls IfOpenDataTyCon  = []
118 visibleIfConDecls IfOpenNewTyCon   = []
119 visibleIfConDecls (IfDataTyCon cs) = cs
120 visibleIfConDecls (IfNewTyCon c)   = [c]
121
122 data IfaceConDecl 
123   = IfCon {
124         ifConOcc     :: OccName,                -- Constructor name
125         ifConInfix   :: Bool,                   -- True <=> declared infix
126         ifConUnivTvs :: [IfaceTvBndr],          -- Universal tyvars
127         ifConExTvs   :: [IfaceTvBndr],          -- Existential tyvars
128         ifConEqSpec  :: [(OccName,IfaceType)],  -- Equality contraints
129         ifConCtxt    :: IfaceContext,           -- Non-stupid context
130         ifConArgTys  :: [IfaceType],            -- Arg types
131         ifConFields  :: [OccName],              -- ...ditto... (field labels)
132         ifConStricts :: [StrictnessMark]}       -- Empty (meaning all lazy),
133                                                 -- or 1-1 corresp with arg tys
134
135 data IfaceInst 
136   = IfaceInst { ifInstCls  :: Name,                     -- See comments with
137                 ifInstTys  :: [Maybe IfaceTyCon],       -- the defn of Instance
138                 ifDFun     :: Name,                     -- The dfun
139                 ifOFlag    :: OverlapFlag,              -- Overlap flag
140                 ifInstOrph :: Maybe OccName }           -- See Note [Orphans]
141         -- There's always a separate IfaceDecl for the DFun, which gives 
142         -- its IdInfo with its full type and version number.
143         -- The instance declarations taken together have a version number,
144         -- and we don't want that to wobble gratuitously
145         -- If this instance decl is *used*, we'll record a usage on the dfun;
146         -- and if the head does not change it won't be used if it wasn't before
147
148 data IfaceFamInst
149   = IfaceFamInst { ifFamInstFam   :: Name                -- Family tycon
150                  , ifFamInstTys   :: [Maybe IfaceTyCon]  -- Rough match types
151                  , ifFamInstTyCon :: IfaceTyCon          -- Instance decl
152                  }
153
154 data IfaceRule
155   = IfaceRule { 
156         ifRuleName   :: RuleName,
157         ifActivation :: Activation,
158         ifRuleBndrs  :: [IfaceBndr],    -- Tyvars and term vars
159         ifRuleHead   :: Name,           -- Head of lhs
160         ifRuleArgs   :: [IfaceExpr],    -- Args of LHS
161         ifRuleRhs    :: IfaceExpr,
162         ifRuleOrph   :: Maybe OccName   -- Just like IfaceInst
163     }
164
165 data IfaceIdInfo
166   = NoInfo                      -- When writing interface file without -O
167   | HasInfo [IfaceInfoItem]     -- Has info, and here it is
168
169 -- Here's a tricky case:
170 --   * Compile with -O module A, and B which imports A.f
171 --   * Change function f in A, and recompile without -O
172 --   * When we read in old A.hi we read in its IdInfo (as a thunk)
173 --      (In earlier GHCs we used to drop IdInfo immediately on reading,
174 --       but we do not do that now.  Instead it's discarded when the
175 --       ModIface is read into the various decl pools.)
176 --   * The version comparsion sees that new (=NoInfo) differs from old (=HasInfo *)
177 --      and so gives a new version.
178
179 data IfaceInfoItem
180   = HsArity      Arity
181   | HsStrictness StrictSig
182   | HsInline     Activation
183   | HsUnfold     IfaceExpr
184   | HsNoCafRefs
185   | HsWorker     Name Arity     -- Worker, if any see IdInfo.WorkerInfo
186                                         -- for why we want arity here.
187         -- NB: we need IfaceExtName (not just OccName) because the worker
188         --     can simplify to a function in another module.
189 -- NB: Specialisations and rules come in separately and are
190 -- only later attached to the Id.  Partial reason: some are orphans.
191
192 --------------------------------
193 data IfaceExpr
194   = IfaceLcl    FastString
195   | IfaceExt    Name
196   | IfaceType   IfaceType
197   | IfaceTuple  Boxity [IfaceExpr]              -- Saturated; type arguments omitted
198   | IfaceLam    IfaceBndr IfaceExpr
199   | IfaceApp    IfaceExpr IfaceExpr
200   | IfaceCase   IfaceExpr FastString IfaceType [IfaceAlt]
201   | IfaceLet    IfaceBinding  IfaceExpr
202   | IfaceNote   IfaceNote IfaceExpr
203   | IfaceCast   IfaceExpr IfaceCoercion
204   | IfaceLit    Literal
205   | IfaceFCall  ForeignCall IfaceType
206
207 data IfaceNote = IfaceSCC CostCentre
208                | IfaceInlineMe
209                | IfaceCoreNote String
210
211 type IfaceAlt = (IfaceConAlt, [FastString], IfaceExpr)
212         -- Note: FastString, not IfaceBndr (and same with the case binder)
213         -- We reconstruct the kind/type of the thing from the context
214         -- thus saving bulk in interface files
215
216 data IfaceConAlt = IfaceDefault
217                  | IfaceDataAlt Name
218                  | IfaceTupleAlt Boxity
219                  | IfaceLitAlt Literal
220
221 data IfaceBinding
222   = IfaceNonRec IfaceIdBndr IfaceExpr
223   | IfaceRec    [(IfaceIdBndr, IfaceExpr)]
224 \end{code}
225
226 Note [Orphans]: the ifInstOrph and ifRuleOrph fields
227 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228 If a module contains any "orphans", then its interface file is read
229 regardless, so that its instances are not missed.
230
231 Roughly speaking, an instance is an orphan if its head (after the =>)
232 mentions nothing defined in this module.  Functional dependencies
233 complicate the situation though. Consider
234
235   module M where { class C a b | a -> b }
236
237 and suppose we are compiling module X:
238
239   module X where
240         import M
241         data T = ...
242         instance C Int T where ...
243
244 This instance is an orphan, because when compiling a third module Y we
245 might get a constraint (C Int v), and we'd want to improve v to T.  So
246 we must make sure X's instances are loaded, even if we do not directly
247 use anything from X.
248
249 More precisely, an instance is an orphan iff
250
251   If there are no fundeps, then at least of the names in
252   the instance head is locally defined.
253
254   If there are fundeps, then for every fundep, at least one of the
255   names free in a *non-determined* part of the instance head is
256   defined in this module.  
257
258 (Note that these conditions hold trivially if the class is locally
259 defined.)
260
261 Note [Versioning of instances]
262 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
263 Now consider versioning.  If we *use* an instance decl in one compilation,
264 we'll depend on the dfun id for that instance, so we'll recompile if it changes.
265 But suppose we *don't* (currently) use an instance!  We must recompile if
266 the instance is changed in such a way that it becomes important.  (This would
267 only matter with overlapping instances, else the importing module wouldn't have
268 compiled before and the recompilation check is irrelevant.)
269
270 The is_orph field is set to (Just n) if the instance is not an orphan.
271 The 'n' is *any* of the locally-defined names mentioned anywhere in the
272 instance head.  This name is used for versioning; the instance decl is
273 considered part of the defn of this 'n'.
274
275 I'm worried about whether this works right if we pick a name from
276 a functionally-dependent part of the instance decl.  E.g.
277
278   module M where { class C a b | a -> b }
279
280 and suppose we are compiling module X:
281
282   module X where
283         import M
284         data S  = ...
285         data T = ...
286         instance C S T where ...
287
288 If we base the instance verion on T, I'm worried that changing S to S'
289 would change T's version, but not S or S'.  But an importing module might
290 not depend on T, and so might not be recompiled even though the new instance
291 (C S' T) might be relevant.  I have not been able to make a concrete example,
292 and it seems deeply obscure, so I'm going to leave it for now.
293
294
295 Note [Versioning of rules]
296 ~~~~~~~~~~~~~~~~~~~~~~~~~~
297 A rule that is not an orphan has an ifRuleOrph field of (Just n), where
298 n appears on the LHS of the rule; any change in the rule changes the version of n.
299
300
301 \begin{code}
302 -- -----------------------------------------------------------------------------
303 -- Utils on IfaceSyn
304
305 ifaceDeclSubBndrs :: IfaceDecl -> [OccName]
306 --  *Excludes* the 'main' name, but *includes* the implicitly-bound names
307 -- Deeply revolting, because it has to predict what gets bound,
308 -- especially the question of whether there's a wrapper for a datacon
309
310 ifaceDeclSubBndrs (IfaceClass {ifCtxt = sc_ctxt, ifName = cls_occ, 
311                                ifSigs = sigs, ifATs = ats })
312   = co_occs ++
313     [tc_occ, dc_occ, dcww_occ] ++
314     [op | IfaceClassOp op  _ _ <- sigs] ++
315     [ifName at | at <- ats ] ++
316     [mkSuperDictSelOcc n cls_occ | n <- [1..n_ctxt]] 
317   where
318     n_ctxt = length sc_ctxt
319     n_sigs = length sigs
320     tc_occ  = mkClassTyConOcc cls_occ
321     dc_occ  = mkClassDataConOcc cls_occ 
322     co_occs | is_newtype = [mkNewTyCoOcc tc_occ]
323             | otherwise  = []
324     dcww_occ -- | is_newtype = mkDataConWrapperOcc dc_occ       -- Newtypes have wrapper but no worker
325              | otherwise  = mkDataConWorkerOcc dc_occ   -- Otherwise worker but no wrapper
326     is_newtype = n_sigs + n_ctxt == 1                   -- Sigh 
327
328 ifaceDeclSubBndrs IfaceData {ifCons = IfAbstractTyCon}
329   = []
330 -- Newtype
331 ifaceDeclSubBndrs (IfaceData {ifName = tc_occ,
332                               ifCons = IfNewTyCon (
333                                          IfCon { ifConOcc = con_occ, 
334                                                            ifConFields = fields
335                                                          }),
336                               ifFamInst = famInst}) 
337   = fields ++ [con_occ, mkDataConWorkerOcc con_occ, mkNewTyCoOcc tc_occ]
338     ++ famInstCo famInst tc_occ
339
340 ifaceDeclSubBndrs (IfaceData {ifName = tc_occ,
341                               ifCons = IfDataTyCon cons, 
342                               ifFamInst = famInst})
343   = nub (concatMap ifConFields cons)    -- Eliminate duplicate fields
344     ++ concatMap dc_occs cons
345     ++ famInstCo famInst tc_occ
346   where
347     dc_occs con_decl
348         | has_wrapper = [con_occ, work_occ, wrap_occ]
349         | otherwise   = [con_occ, work_occ]
350         where
351           con_occ = ifConOcc con_decl
352           strs    = ifConStricts con_decl
353           wrap_occ = mkDataConWrapperOcc con_occ
354           work_occ = mkDataConWorkerOcc con_occ
355           has_wrapper = any isMarkedStrict strs -- See MkId.mkDataConIds (sigh)
356                         || not (null . ifConEqSpec $ con_decl)
357                         || isJust famInst
358                 -- ToDo: may miss strictness in existential dicts
359
360 ifaceDeclSubBndrs _other = []
361
362 -- coercion for data/newtype family instances
363 famInstCo Nothing  baseOcc = []
364 famInstCo (Just _) baseOcc = [mkInstTyCoOcc baseOcc]
365
366 ----------------------------- Printing IfaceDecl ------------------------------
367
368 instance Outputable IfaceDecl where
369   ppr = pprIfaceDecl
370
371 pprIfaceDecl (IfaceId {ifName = var, ifType = ty, ifIdInfo = info})
372   = sep [ ppr var <+> dcolon <+> ppr ty, 
373           nest 2 (ppr info) ]
374
375 pprIfaceDecl (IfaceForeign {ifName = tycon})
376   = hsep [ptext SLIT("foreign import type dotnet"), ppr tycon]
377
378 pprIfaceDecl (IfaceSyn {ifName = tycon, ifTyVars = tyvars, 
379                         ifOpenSyn = False, ifSynRhs = mono_ty})
380   = hang (ptext SLIT("type") <+> pprIfaceDeclHead [] tycon tyvars)
381        4 (equals <+> ppr mono_ty)
382
383 pprIfaceDecl (IfaceSyn {ifName = tycon, ifTyVars = tyvars, 
384                         ifOpenSyn = True, ifSynRhs = mono_ty})
385   = hang (ptext SLIT("type family") <+> pprIfaceDeclHead [] tycon tyvars)
386        4 (dcolon <+> ppr mono_ty)
387
388 pprIfaceDecl (IfaceData {ifName = tycon, ifGeneric = gen, ifCtxt = context,
389                          ifTyVars = tyvars, ifCons = condecls, 
390                          ifRec = isrec, ifFamInst = mbFamInst})
391   = hang (pp_nd <+> pprIfaceDeclHead context tycon tyvars)
392        4 (vcat [pprRec isrec, pprGen gen, pp_condecls tycon condecls,
393                 pprFamily mbFamInst])
394   where
395     pp_nd = case condecls of
396                 IfAbstractTyCon -> ptext SLIT("data")
397                 IfOpenDataTyCon -> ptext SLIT("data family")
398                 IfDataTyCon _   -> ptext SLIT("data")
399                 IfNewTyCon _    -> ptext SLIT("newtype")
400                 IfOpenNewTyCon  -> ptext SLIT("newtype family")
401
402 pprIfaceDecl (IfaceClass {ifCtxt = context, ifName = clas, ifTyVars = tyvars, 
403                           ifFDs = fds, ifATs = ats, ifSigs = sigs, 
404                           ifRec = isrec})
405   = hang (ptext SLIT("class") <+> pprIfaceDeclHead context clas tyvars <+> pprFundeps fds)
406        4 (vcat [pprRec isrec,
407                 sep (map ppr ats),
408                 sep (map ppr sigs)])
409
410 pprRec isrec = ptext SLIT("RecFlag") <+> ppr isrec
411 pprGen True  = ptext SLIT("Generics: yes")
412 pprGen False = ptext SLIT("Generics: no")
413
414 pprFamily Nothing        = ptext SLIT("FamilyInstance: none")
415 pprFamily (Just famInst) = ptext SLIT("FamilyInstance:") <+> ppr famInst
416
417 instance Outputable IfaceClassOp where
418    ppr (IfaceClassOp n dm ty) = ppr n <+> ppr dm <+> dcolon <+> ppr ty
419
420 pprIfaceDeclHead :: IfaceContext -> OccName -> [IfaceTvBndr] -> SDoc
421 pprIfaceDeclHead context thing tyvars
422   = hsep [pprIfaceContext context, parenSymOcc thing (ppr thing), 
423           pprIfaceTvBndrs tyvars]
424
425 pp_condecls tc IfAbstractTyCon  = ptext SLIT("{- abstract -}")
426 pp_condecls tc IfOpenNewTyCon   = empty
427 pp_condecls tc (IfNewTyCon c)   = equals <+> pprIfaceConDecl tc c
428 pp_condecls tc IfOpenDataTyCon  = empty
429 pp_condecls tc (IfDataTyCon cs) = equals <+> sep (punctuate (ptext SLIT(" |"))
430                                                              (map (pprIfaceConDecl tc) cs))
431
432 pprIfaceConDecl :: OccName -> IfaceConDecl -> SDoc
433 pprIfaceConDecl tc
434         (IfCon { ifConOcc = name, ifConInfix = is_infix, 
435                  ifConUnivTvs = univ_tvs, ifConExTvs = ex_tvs, 
436                  ifConEqSpec = eq_spec, ifConCtxt = ctxt, ifConArgTys = arg_tys, 
437                  ifConStricts = strs, ifConFields = fields })
438   = sep [main_payload,
439          if is_infix then ptext SLIT("Infix") else empty,
440          if null strs then empty 
441               else nest 4 (ptext SLIT("Stricts:") <+> hsep (map ppr strs)),
442          if null fields then empty
443               else nest 4 (ptext SLIT("Fields:") <+> hsep (map ppr fields))]
444   where
445     main_payload = ppr name <+> dcolon <+> 
446                    pprIfaceForAllPart (univ_tvs ++ ex_tvs) (eq_ctxt ++ ctxt) pp_tau
447
448     eq_ctxt = [(IfaceEqPred (IfaceTyVar (occNameFS tv)) ty) 
449               | (tv,ty) <- eq_spec] 
450
451         -- A bit gruesome this, but we can't form the full con_tau, and ppr it,
452         -- because we don't have a Name for the tycon, only an OccName
453     pp_tau = case map pprParendIfaceType arg_tys ++ [pp_res_ty] of
454                 (t:ts) -> fsep (t : map (arrow <+>) ts)
455                 []     -> panic "pp_con_taus"
456
457     pp_res_ty = ppr tc <+> fsep [ppr tv | (tv,_) <- univ_tvs]
458
459 instance Outputable IfaceRule where
460   ppr (IfaceRule { ifRuleName = name, ifActivation = act, ifRuleBndrs = bndrs,
461                    ifRuleHead = fn, ifRuleArgs = args, ifRuleRhs = rhs }) 
462     = sep [hsep [doubleQuotes (ftext name), ppr act,
463                  ptext SLIT("forall") <+> pprIfaceBndrs bndrs],
464            nest 2 (sep [ppr fn <+> sep (map (pprIfaceExpr parens) args),
465                         ptext SLIT("=") <+> ppr rhs])
466       ]
467
468 instance Outputable IfaceInst where
469   ppr (IfaceInst {ifDFun = dfun_id, ifOFlag = flag, 
470                   ifInstCls = cls, ifInstTys = mb_tcs})
471     = hang (ptext SLIT("instance") <+> ppr flag 
472                 <+> ppr cls <+> brackets (pprWithCommas ppr_rough mb_tcs))
473          2 (equals <+> ppr dfun_id)
474
475 instance Outputable IfaceFamInst where
476   ppr (IfaceFamInst {ifFamInstFam = fam, ifFamInstTys = mb_tcs,
477                      ifFamInstTyCon = tycon_id})
478     = hang (ptext SLIT("family instance") <+> 
479             ppr fam <+> brackets (pprWithCommas ppr_rough mb_tcs))
480          2 (equals <+> ppr tycon_id)
481
482 ppr_rough :: Maybe IfaceTyCon -> SDoc
483 ppr_rough Nothing   = dot
484 ppr_rough (Just tc) = ppr tc
485 \end{code}
486
487
488 ----------------------------- Printing IfaceExpr ------------------------------------
489
490 \begin{code}
491 instance Outputable IfaceExpr where
492     ppr e = pprIfaceExpr noParens e
493
494 pprIfaceExpr :: (SDoc -> SDoc) -> IfaceExpr -> SDoc
495         -- The function adds parens in context that need
496         -- an atomic value (e.g. function args)
497
498 pprIfaceExpr add_par (IfaceLcl v)       = ppr v
499 pprIfaceExpr add_par (IfaceExt v)       = ppr v
500 pprIfaceExpr add_par (IfaceLit l)       = ppr l
501 pprIfaceExpr add_par (IfaceFCall cc ty) = braces (ppr cc <+> ppr ty)
502 pprIfaceExpr add_par (IfaceType ty)     = char '@' <+> pprParendIfaceType ty
503
504 pprIfaceExpr add_par app@(IfaceApp _ _) = add_par (pprIfaceApp app [])
505 pprIfaceExpr add_par (IfaceTuple c as)  = tupleParens c (interpp'SP as)
506
507 pprIfaceExpr add_par e@(IfaceLam _ _)   
508   = add_par (sep [char '\\' <+> sep (map ppr bndrs) <+> arrow,
509                   pprIfaceExpr noParens body])
510   where 
511     (bndrs,body) = collect [] e
512     collect bs (IfaceLam b e) = collect (b:bs) e
513     collect bs e              = (reverse bs, e)
514
515 pprIfaceExpr add_par (IfaceCase scrut bndr ty [(con, bs, rhs)])
516   = add_par (sep [ptext SLIT("case") <+> char '@' <+> pprParendIfaceType ty
517                         <+> pprIfaceExpr noParens scrut <+> ptext SLIT("of") 
518                         <+> ppr bndr <+> char '{' <+> ppr_con_bs con bs <+> arrow,
519                   pprIfaceExpr noParens rhs <+> char '}'])
520
521 pprIfaceExpr add_par (IfaceCase scrut bndr ty alts)
522   = add_par (sep [ptext SLIT("case") <+> char '@' <+> pprParendIfaceType ty
523                         <+> pprIfaceExpr noParens scrut <+> ptext SLIT("of") 
524                         <+> ppr bndr <+> char '{',
525                   nest 2 (sep (map ppr_alt alts)) <+> char '}'])
526
527 pprIfaceExpr add_par (IfaceCast expr co)
528   = sep [pprIfaceExpr parens expr,
529          nest 2 (ptext SLIT("`cast`")),
530          pprParendIfaceType co]
531
532 pprIfaceExpr add_par (IfaceLet (IfaceNonRec b rhs) body)
533   = add_par (sep [ptext SLIT("let {"), 
534                   nest 2 (ppr_bind (b, rhs)),
535                   ptext SLIT("} in"), 
536                   pprIfaceExpr noParens body])
537
538 pprIfaceExpr add_par (IfaceLet (IfaceRec pairs) body)
539   = add_par (sep [ptext SLIT("letrec {"),
540                   nest 2 (sep (map ppr_bind pairs)), 
541                   ptext SLIT("} in"),
542                   pprIfaceExpr noParens body])
543
544 pprIfaceExpr add_par (IfaceNote note body) = add_par (ppr note <+> pprIfaceExpr parens body)
545
546 ppr_alt (con, bs, rhs) = sep [ppr_con_bs con bs, 
547                               arrow <+> pprIfaceExpr noParens rhs]
548
549 ppr_con_bs (IfaceTupleAlt tup_con) bs = tupleParens tup_con (interpp'SP bs)
550 ppr_con_bs con bs                     = ppr con <+> hsep (map ppr bs)
551   
552 ppr_bind ((b,ty),rhs) = sep [ppr b <+> dcolon <+> ppr ty, 
553                              equals <+> pprIfaceExpr noParens rhs]
554
555 ------------------
556 pprIfaceApp (IfaceApp fun arg) args = pprIfaceApp fun (nest 2 (pprIfaceExpr parens arg) : args)
557 pprIfaceApp fun                args = sep (pprIfaceExpr parens fun : args)
558
559 ------------------
560 instance Outputable IfaceNote where
561     ppr (IfaceSCC cc)     = pprCostCentreCore cc
562     ppr IfaceInlineMe     = ptext SLIT("__inline_me")
563     ppr (IfaceCoreNote s) = ptext SLIT("__core_note") <+> pprHsString (mkFastString s)
564
565
566 instance Outputable IfaceConAlt where
567     ppr IfaceDefault      = text "DEFAULT"
568     ppr (IfaceLitAlt l)   = ppr l
569     ppr (IfaceDataAlt d)  = ppr d
570     ppr (IfaceTupleAlt b) = panic "ppr IfaceConAlt" 
571         -- IfaceTupleAlt is handled by the case-alternative printer
572
573 ------------------
574 instance Outputable IfaceIdInfo where
575    ppr NoInfo       = empty
576    ppr (HasInfo is) = ptext SLIT("{-") <+> fsep (map ppr_hs_info is) <+> ptext SLIT("-}")
577
578 ppr_hs_info (HsUnfold unf)      = ptext SLIT("Unfolding:") <+>
579                                         parens (pprIfaceExpr noParens unf)
580 ppr_hs_info (HsInline act)      = ptext SLIT("Inline:") <+> ppr act
581 ppr_hs_info (HsArity arity)     = ptext SLIT("Arity:") <+> int arity
582 ppr_hs_info (HsStrictness str)  = ptext SLIT("Strictness:") <+> pprIfaceStrictSig str
583 ppr_hs_info HsNoCafRefs         = ptext SLIT("HasNoCafRefs")
584 ppr_hs_info (HsWorker w a)      = ptext SLIT("Worker:") <+> ppr w <+> int a
585 \end{code}
586
587
588 %************************************************************************
589 %*                                                                      *
590         Equality, for interface file version generaion only
591 %*                                                                      *
592 %************************************************************************
593
594 Equality over IfaceSyn returns an IfaceEq, not a Bool.  The new
595 constructor is EqBut, which gives the set of things whose version must
596 be equal for the whole thing to be equal.  So the key function is
597 eqIfExt, which compares Names.
598
599 Of course, equality is also done modulo alpha conversion.
600
601 \begin{code}
602 data GenIfaceEq a
603   = Equal               -- Definitely exactly the same
604   | NotEqual            -- Definitely different
605   | EqBut a       -- The same provided these Names have not changed
606
607 type IfaceEq = GenIfaceEq NameSet
608
609 instance Outputable IfaceEq where
610   ppr Equal          = ptext SLIT("Equal")
611   ppr NotEqual       = ptext SLIT("NotEqual")
612   ppr (EqBut occset) = ptext SLIT("EqBut") <+> ppr (nameSetToList occset)
613
614 bool :: Bool -> IfaceEq
615 bool True  = Equal
616 bool False = NotEqual
617
618 toBool :: IfaceEq -> Bool
619 toBool Equal     = True
620 toBool (EqBut _) = True
621 toBool NotEqual  = False
622
623 zapEq :: IfaceEq -> IfaceEq     -- Used to forget EqBut information
624 zapEq (EqBut _) = Equal
625 zapEq other     = other
626
627 (&&&) :: IfaceEq -> IfaceEq -> IfaceEq
628 Equal       &&& x           = x
629 NotEqual    &&& x           = NotEqual
630 EqBut nms   &&& Equal       = EqBut nms
631 EqBut nms   &&& NotEqual    = NotEqual
632 EqBut nms1  &&& EqBut nms2  = EqBut (nms1 `unionNameSets` nms2)
633
634 -- This function is the core of the EqBut stuff
635 -- ASSUMPTION: The left-hand argument is the NEW CODE, and hence
636 -- any Names in the left-hand arg have the correct parent in them.
637 eqIfExt :: Name -> Name -> IfaceEq
638 eqIfExt name1 name2 
639   | name1 == name2 = EqBut (unitNameSet name1)
640   | otherwise      = NotEqual
641
642 ---------------------
643 checkBootDecl :: IfaceDecl      -- The boot decl
644               -> IfaceDecl      -- The real decl
645               -> Bool           -- True <=> compatible
646 checkBootDecl (IfaceId s1 t1 _) (IfaceId s2 t2 _)
647   = ASSERT( s1==s2 ) toBool (t1 `eqIfType` t2)
648
649 checkBootDecl d1@(IfaceForeign {}) d2@(IfaceForeign {})
650   = ASSERT (ifName d1 == ifName d2 ) ifExtName d1 == ifExtName d2
651
652 checkBootDecl d1@(IfaceSyn {}) d2@(IfaceSyn {})
653   = ASSERT( ifName d1 == ifName d2 )
654     toBool $ eqWith (ifTyVars d1) (ifTyVars d2) $ \ env -> 
655           eq_ifType env (ifSynRhs d1) (ifSynRhs d2)
656
657 checkBootDecl d1@(IfaceData {}) d2@(IfaceData {})
658 -- We don't check the recursion flags because the boot-one is
659 -- recursive, to be conservative, but the real one may not be.
660 -- I'm not happy with the way recursive flags are dealt with.
661   = ASSERT( ifName d1    == ifName d2 ) 
662     toBool $ eqWith (ifTyVars d1) (ifTyVars d2) $ \ env -> 
663         eq_ifContext env (ifCtxt d1) (ifCtxt d2) &&& 
664         case ifCons d1 of
665             IfAbstractTyCon -> Equal
666             cons1           -> eq_hsCD env cons1 (ifCons d2)
667
668 checkBootDecl d1@(IfaceClass {}) d2@(IfaceClass {})
669   = ASSERT( ifName d1 == ifName d2 )
670     toBool $ eqWith (ifTyVars d1) (ifTyVars d2) $ \ env -> 
671           eqListBy (eq_hsFD env)    (ifFDs d1)  (ifFDs d2) &&&
672           case (ifCtxt d1, ifSigs d1) of
673              ([], [])      -> Equal
674              (cxt1, sigs1) -> eq_ifContext env cxt1 (ifCtxt d2)  &&&
675                               eqListBy (eq_cls_sig env) sigs1 (ifSigs d2)
676
677 checkBootDecl _ _ = False       -- default case
678
679 ---------------------
680 eqIfDecl :: IfaceDecl -> IfaceDecl -> IfaceEq
681 eqIfDecl (IfaceId s1 t1 i1) (IfaceId s2 t2 i2)
682   = bool (s1 == s2) &&& (t1 `eqIfType` t2) &&& (i1 `eqIfIdInfo` i2)
683
684 eqIfDecl d1@(IfaceForeign {}) d2@(IfaceForeign {})
685   = bool (ifName d1 == ifName d2 && ifExtName d1 == ifExtName d2)
686
687 eqIfDecl d1@(IfaceData {}) d2@(IfaceData {})
688   = bool (ifName d1    == ifName d2 && 
689           ifRec d1     == ifRec   d2 && 
690           ifGadtSyntax d1 == ifGadtSyntax   d2 && 
691           ifGeneric d1 == ifGeneric d2) &&&
692     ifFamInst d1 `eqIfTc_fam` ifFamInst d2 &&&
693     eqWith (ifTyVars d1) (ifTyVars d2) (\ env -> 
694             eq_ifContext env (ifCtxt d1) (ifCtxt d2) &&& 
695             eq_hsCD env (ifCons d1) (ifCons d2) 
696         )
697         -- The type variables of the data type do not scope
698         -- over the constructors (any more), but they do scope
699         -- over the stupid context in the IfaceConDecls
700   where
701     Nothing             `eqIfTc_fam` Nothing             = Equal
702     (Just (fam1, tys1)) `eqIfTc_fam` (Just (fam2, tys2)) = 
703       fam1 `eqIfTc` fam2 &&& eqListBy eqIfType tys1 tys2
704     _                   `eqIfTc_fam` _                   = NotEqual
705
706 eqIfDecl d1@(IfaceSyn {}) d2@(IfaceSyn {})
707   = bool (ifName d1 == ifName d2) &&&
708     eqWith (ifTyVars d1) (ifTyVars d2) (\ env -> 
709           eq_ifType env (ifSynRhs d1) (ifSynRhs d2)
710         )
711
712 eqIfDecl d1@(IfaceClass {}) d2@(IfaceClass {})
713   = bool (ifName d1 == ifName d2 && 
714           ifRec d1  == ifRec  d2) &&&
715     eqWith (ifTyVars d1) (ifTyVars d2) (\ env -> 
716           eq_ifContext env (ifCtxt d1) (ifCtxt d2)  &&&
717           eqListBy (eq_hsFD env)    (ifFDs d1)  (ifFDs d2) &&&
718           eqListBy eqIfDecl         (ifATs d1)  (ifATs d2) &&&
719           eqListBy (eq_cls_sig env) (ifSigs d1) (ifSigs d2)
720        )
721
722 eqIfDecl _ _ = NotEqual -- default case
723
724 -- Helper
725 eqWith :: [IfaceTvBndr] -> [IfaceTvBndr] -> (EqEnv -> IfaceEq) -> IfaceEq
726 eqWith = eq_ifTvBndrs emptyEqEnv
727
728 -----------------------
729 eqIfInst d1 d2 = bool (ifDFun d1 == ifDFun d2 && ifOFlag d1 == ifOFlag d2)
730 -- All other changes are handled via the version info on the dfun
731
732 eqIfFamInst d1 d2 = bool (ifFamInstTyCon d1 == ifFamInstTyCon d2)
733 -- All other changes are handled via the version info on the tycon
734
735 eqIfRule (IfaceRule n1 a1 bs1 f1 es1 rhs1 o1)
736          (IfaceRule n2 a2 bs2 f2 es2 rhs2 o2)
737        = bool (n1==n2 && a1==a2 && o1 == o2) &&&
738          f1 `eqIfExt` f2 &&&
739          eq_ifBndrs emptyEqEnv bs1 bs2 (\env -> 
740          zapEq (eqListBy (eq_ifaceExpr env) es1 es2) &&&
741                 -- zapEq: for the LHSs, ignore the EqBut part
742          eq_ifaceExpr env rhs1 rhs2)
743
744 eq_hsCD env (IfDataTyCon c1) (IfDataTyCon c2) 
745   = eqListBy (eq_ConDecl env) c1 c2
746
747 eq_hsCD env (IfNewTyCon c1)  (IfNewTyCon c2)  = eq_ConDecl env c1 c2
748 eq_hsCD env IfAbstractTyCon  IfAbstractTyCon  = Equal
749 eq_hsCD env IfOpenDataTyCon  IfOpenDataTyCon  = Equal
750 eq_hsCD env IfOpenNewTyCon   IfOpenNewTyCon   = Equal
751 eq_hsCD env d1               d2               = NotEqual
752
753 eq_ConDecl env c1 c2
754   = bool (ifConOcc c1     == ifConOcc c2 && 
755           ifConInfix c1   == ifConInfix c2 && 
756           ifConStricts c1 == ifConStricts c2 && 
757           ifConFields c1  == ifConFields c2) &&&
758     eq_ifTvBndrs env (ifConUnivTvs c1) (ifConUnivTvs c2) (\ env ->
759     eq_ifTvBndrs env (ifConExTvs c1) (ifConExTvs c2) (\ env ->
760         eq_ifContext env (ifConCtxt c1) (ifConCtxt c2) &&&
761         eq_ifTypes env (ifConArgTys c1) (ifConArgTys c2)))
762
763 eq_hsFD env (ns1,ms1) (ns2,ms2)
764   = eqListBy (eqIfOcc env) ns1 ns2 &&& eqListBy (eqIfOcc env) ms1 ms2
765
766 eq_cls_sig env (IfaceClassOp n1 dm1 ty1) (IfaceClassOp n2 dm2 ty2)
767   = bool (n1==n2 && dm1 == dm2) &&& eq_ifType env ty1 ty2
768 \end{code}
769
770
771 \begin{code}
772 -----------------
773 eqIfIdInfo NoInfo        NoInfo        = Equal
774 eqIfIdInfo (HasInfo is1) (HasInfo is2) = eqListBy eq_item is1 is2
775 eqIfIdInfo i1            i2 = NotEqual
776
777 eq_item (HsInline a1)      (HsInline a2)      = bool (a1 == a2)
778 eq_item (HsArity a1)       (HsArity a2)       = bool (a1 == a2)
779 eq_item (HsStrictness s1)  (HsStrictness s2)  = bool (s1 == s2)
780 eq_item (HsUnfold u1)   (HsUnfold u2)         = eq_ifaceExpr emptyEqEnv u1 u2
781 eq_item HsNoCafRefs        HsNoCafRefs        = Equal
782 eq_item (HsWorker wkr1 a1) (HsWorker wkr2 a2) = bool (a1==a2) &&& (wkr1 `eqIfExt` wkr2)
783 eq_item _ _ = NotEqual
784
785 -----------------
786 eq_ifaceExpr :: EqEnv -> IfaceExpr -> IfaceExpr -> IfaceEq
787 eq_ifaceExpr env (IfaceLcl v1)        (IfaceLcl v2)        = eqIfOcc env v1 v2
788 eq_ifaceExpr env (IfaceExt v1)        (IfaceExt v2)        = eqIfExt v1 v2
789 eq_ifaceExpr env (IfaceLit l1)        (IfaceLit l2)        = bool (l1 == l2)
790 eq_ifaceExpr env (IfaceFCall c1 ty1)  (IfaceFCall c2 ty2)  = bool (c1==c2) &&& eq_ifType env ty1 ty2
791 eq_ifaceExpr env (IfaceType ty1)      (IfaceType ty2)      = eq_ifType env ty1 ty2
792 eq_ifaceExpr env (IfaceTuple n1 as1)  (IfaceTuple n2 as2)  = bool (n1==n2) &&& eqListBy (eq_ifaceExpr env) as1 as2
793 eq_ifaceExpr env (IfaceLam b1 body1)  (IfaceLam b2 body2)  = eq_ifBndr env b1 b2 (\env -> eq_ifaceExpr env body1 body2)
794 eq_ifaceExpr env (IfaceApp f1 a1)     (IfaceApp f2 a2)     = eq_ifaceExpr env f1 f2 &&& eq_ifaceExpr env a1 a2
795 eq_ifaceExpr env (IfaceCast e1 co1)   (IfaceCast e2 co2)   = eq_ifaceExpr env e1 e2 &&& eq_ifType env co1 co2
796 eq_ifaceExpr env (IfaceNote n1 r1)    (IfaceNote n2 r2)    = eq_ifaceNote env n1 n2 &&& eq_ifaceExpr env r1 r2
797
798 eq_ifaceExpr env (IfaceCase s1 b1 ty1 as1) (IfaceCase s2 b2 ty2 as2)
799   = eq_ifaceExpr env s1 s2 &&&
800     eq_ifType env ty1 ty2 &&&
801     eq_ifNakedBndr env b1 b2 (\env -> eqListBy (eq_ifaceAlt env) as1 as2)
802   where
803     eq_ifaceAlt env (c1,bs1,r1) (c2,bs2,r2)
804         = bool (eq_ifaceConAlt c1 c2) &&& 
805           eq_ifNakedBndrs env bs1 bs2 (\env -> eq_ifaceExpr env r1 r2)
806
807 eq_ifaceExpr env (IfaceLet (IfaceNonRec b1 r1) x1) (IfaceLet (IfaceNonRec b2 r2) x2)
808   = eq_ifaceExpr env r1 r2 &&& eq_ifIdBndr env b1 b2 (\env -> eq_ifaceExpr env x1 x2)
809
810 eq_ifaceExpr env (IfaceLet (IfaceRec as1) x1) (IfaceLet (IfaceRec as2) x2)
811   = eq_ifIdBndrs env bs1 bs2 (\env -> eqListBy (eq_ifaceExpr env) rs1 rs2 &&& eq_ifaceExpr env x1 x2)
812   where
813     (bs1,rs1) = unzip as1
814     (bs2,rs2) = unzip as2
815
816
817 eq_ifaceExpr env _ _ = NotEqual
818
819 -----------------
820 eq_ifaceConAlt :: IfaceConAlt -> IfaceConAlt -> Bool
821 eq_ifaceConAlt IfaceDefault       IfaceDefault          = True
822 eq_ifaceConAlt (IfaceDataAlt n1)  (IfaceDataAlt n2)     = n1==n2
823 eq_ifaceConAlt (IfaceTupleAlt c1) (IfaceTupleAlt c2)    = c1==c2
824 eq_ifaceConAlt (IfaceLitAlt l1)   (IfaceLitAlt l2)      = l1==l2
825 eq_ifaceConAlt _ _ = False
826
827 -----------------
828 eq_ifaceNote :: EqEnv -> IfaceNote -> IfaceNote -> IfaceEq
829 eq_ifaceNote env (IfaceSCC c1)    (IfaceSCC c2)        = bool (c1==c2)
830 eq_ifaceNote env IfaceInlineMe    IfaceInlineMe        = Equal
831 eq_ifaceNote env (IfaceCoreNote s1) (IfaceCoreNote s2) = bool (s1==s2)
832 eq_ifaceNote env _ _ = NotEqual
833 \end{code}
834
835 \begin{code}
836 ---------------------
837 eqIfType t1 t2 = eq_ifType emptyEqEnv t1 t2
838
839 -------------------
840 eq_ifType env (IfaceTyVar n1)         (IfaceTyVar n2)         = eqIfOcc env n1 n2
841 eq_ifType env (IfaceAppTy s1 t1)      (IfaceAppTy s2 t2)      = eq_ifType env s1 s2 &&& eq_ifType env t1 t2
842 eq_ifType env (IfacePredTy st1)       (IfacePredTy st2)       = eq_ifPredType env st1 st2
843 eq_ifType env (IfaceTyConApp tc1 ts1) (IfaceTyConApp tc2 ts2) = tc1 `eqIfTc` tc2 &&& eq_ifTypes env ts1 ts2
844 eq_ifType env (IfaceForAllTy tv1 t1)  (IfaceForAllTy tv2 t2)  = eq_ifTvBndr env tv1 tv2 (\env -> eq_ifType env t1 t2)
845 eq_ifType env (IfaceFunTy s1 t1)      (IfaceFunTy s2 t2)      = eq_ifType env s1 s2 &&& eq_ifType env t1 t2
846 eq_ifType env _ _ = NotEqual
847
848 -------------------
849 eq_ifTypes env = eqListBy (eq_ifType env)
850
851 -------------------
852 eq_ifContext env a b = eqListBy (eq_ifPredType env) a b
853
854 -------------------
855 eq_ifPredType env (IfaceClassP c1 tys1) (IfaceClassP c2 tys2) = c1 `eqIfExt` c2 &&&  eq_ifTypes env tys1 tys2
856 eq_ifPredType env (IfaceIParam n1 ty1) (IfaceIParam n2 ty2)   = bool (n1 == n2) &&& eq_ifType env ty1 ty2
857 eq_ifPredType env _ _ = NotEqual
858
859 -------------------
860 eqIfTc (IfaceTc tc1) (IfaceTc tc2) = tc1 `eqIfExt` tc2
861 eqIfTc IfaceIntTc    IfaceIntTc    = Equal
862 eqIfTc IfaceCharTc   IfaceCharTc   = Equal
863 eqIfTc IfaceBoolTc   IfaceBoolTc   = Equal
864 eqIfTc IfaceListTc   IfaceListTc   = Equal
865 eqIfTc IfacePArrTc   IfacePArrTc   = Equal
866 eqIfTc (IfaceTupTc bx1 ar1) (IfaceTupTc bx2 ar2) = bool (bx1==bx2 && ar1==ar2)
867 eqIfTc IfaceLiftedTypeKindTc   IfaceLiftedTypeKindTc   = Equal
868 eqIfTc IfaceOpenTypeKindTc     IfaceOpenTypeKindTc     = Equal
869 eqIfTc IfaceUnliftedTypeKindTc IfaceUnliftedTypeKindTc = Equal
870 eqIfTc IfaceUbxTupleKindTc     IfaceUbxTupleKindTc     = Equal
871 eqIfTc IfaceArgTypeKindTc      IfaceArgTypeKindTc      = Equal
872 eqIfTc _                       _                       = NotEqual
873 \end{code}
874
875 -----------------------------------------------------------
876         Support code for equality checking
877 -----------------------------------------------------------
878
879 \begin{code}
880 ------------------------------------
881 type EqEnv = UniqFM FastString  -- Tracks the mapping from L-variables to R-variables
882
883 eqIfOcc :: EqEnv -> FastString -> FastString -> IfaceEq
884 eqIfOcc env n1 n2 = case lookupUFM env n1 of
885                         Just n1 -> bool (n1 == n2)
886                         Nothing -> bool (n1 == n2)
887
888 extendEqEnv :: EqEnv -> FastString -> FastString -> EqEnv
889 extendEqEnv env n1 n2 | n1 == n2  = env
890                       | otherwise = addToUFM env n1 n2
891
892 emptyEqEnv :: EqEnv
893 emptyEqEnv = emptyUFM
894
895 ------------------------------------
896 type ExtEnv bndr = EqEnv -> bndr -> bndr -> (EqEnv -> IfaceEq) -> IfaceEq
897
898 eq_ifNakedBndr :: ExtEnv FastString
899 eq_ifBndr      :: ExtEnv IfaceBndr
900 eq_ifTvBndr    :: ExtEnv IfaceTvBndr
901 eq_ifIdBndr    :: ExtEnv IfaceIdBndr
902
903 eq_ifNakedBndr env n1 n2 k = k (extendEqEnv env n1 n2)
904
905 eq_ifBndr env (IfaceIdBndr b1) (IfaceIdBndr b2) k = eq_ifIdBndr env b1 b2 k
906 eq_ifBndr env (IfaceTvBndr b1) (IfaceTvBndr b2) k = eq_ifTvBndr env b1 b2 k
907 eq_ifBndr _ _ _ _ = NotEqual
908
909 eq_ifTvBndr env (v1, k1) (v2, k2) k = eq_ifType env k1 k2 &&& k (extendEqEnv env v1 v2)
910 eq_ifIdBndr env (v1, t1) (v2, t2) k = eq_ifType env t1 t2 &&& k (extendEqEnv env v1 v2)
911
912 eq_ifBndrs      :: ExtEnv [IfaceBndr]
913 eq_ifIdBndrs    :: ExtEnv [IfaceIdBndr]
914 eq_ifTvBndrs    :: ExtEnv [IfaceTvBndr]
915 eq_ifNakedBndrs :: ExtEnv [FastString]
916 eq_ifBndrs      = eq_bndrs_with eq_ifBndr
917 eq_ifIdBndrs    = eq_bndrs_with eq_ifIdBndr
918 eq_ifTvBndrs    = eq_bndrs_with eq_ifTvBndr
919 eq_ifNakedBndrs = eq_bndrs_with eq_ifNakedBndr
920
921 eq_bndrs_with eq env []       []       k = k env
922 eq_bndrs_with eq env (b1:bs1) (b2:bs2) k = eq env b1 b2 (\env -> eq_bndrs_with eq env bs1 bs2 k)
923 eq_bndrs_with eq env _        _        _ = NotEqual
924 \end{code}
925
926 \begin{code}
927 eqListBy :: (a->a->IfaceEq) -> [a] -> [a] -> IfaceEq
928 eqListBy eq []     []     = Equal
929 eqListBy eq (x:xs) (y:ys) = eq x y &&& eqListBy eq xs ys
930 eqListBy eq xs     ys     = NotEqual
931
932 eqMaybeBy :: (a->a->IfaceEq) -> Maybe a -> Maybe a -> IfaceEq
933 eqMaybeBy eq Nothing Nothing   = Equal
934 eqMaybeBy eq (Just x) (Just y) = eq x y
935 eqMaybeBy eq x        y        = NotEqual
936 \end{code}