088de6a2fa9f790a136aa1577da7be8e27a9de9e
[ghc-hetmet.git] / ghc / compiler / main / MkIface.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1998
3 %
4 \section[MkIface]{Print an interface for a module}
5
6 \begin{code}
7 module MkIface (
8         startIface, endIface,
9         ifaceMain,
10         ifaceDecls
11     ) where
12
13 #include "HsVersions.h"
14
15 import IO               ( Handle, hPutStr, openFile, 
16                           hClose, hPutStrLn, IOMode(..) )
17
18 import HsSyn
19 import BasicTypes       ( Fixity(..), FixityDirection(..), NewOrData(..),
20                           StrictnessMark(..) 
21                         )
22 import RnMonad
23 import RnEnv            ( availName )
24
25 import TcInstUtil       ( InstInfo(..) )
26 import WorkWrap         ( getWorkerIdAndCons )
27
28 import CmdLineOpts
29 import Id               ( Id, idType, idInfo, omitIfaceSigForId,
30                           getIdSpecialisation
31                         )
32 import Var              ( isId )
33 import VarSet
34 import DataCon          ( dataConSig, dataConFieldLabels, dataConStrictMarks )
35 import IdInfo           ( IdInfo, StrictnessInfo, ArityInfo, InlinePragInfo(..), inlinePragInfo,
36                           arityInfo, ppArityInfo, 
37                           strictnessInfo, ppStrictnessInfo, 
38                           cafInfo, ppCafInfo,
39                           workerExists, isBottomingStrictness
40                         )
41 import CoreSyn          ( CoreExpr, CoreBind, Bind(..) )
42 import CoreUtils        ( exprSomeFreeVars )
43 import CoreUnfold       ( calcUnfoldingGuidance, UnfoldingGuidance(..), 
44                           Unfolding, okToUnfoldInHiFile )
45 import Module           ( moduleString, pprModule, pprModuleBoot )
46 import Name             ( isLocallyDefined, isWiredInName, nameRdrName, nameModule,
47                           isExported,
48                           Name, NamedThing(..)
49                         )
50 import OccName          ( OccName, pprOccName )
51 import TyCon            ( TyCon, getSynTyConDefn, isSynTyCon, isNewTyCon, isAlgTyCon,
52                           tyConTheta, tyConTyVars, tyConDataCons
53                         )
54 import Class            ( Class, classBigSig )
55 import SpecEnv          ( specEnvToList )
56 import FieldLabel       ( fieldLabelName, fieldLabelType )
57 import Type             ( mkSigmaTy, splitSigmaTy, mkDictTy, tidyTopType, deNoteType,
58                           Type, ThetaType
59                         )
60
61 import PprType
62 import PprCore          ( pprIfaceUnfolding )
63
64 import Bag              ( bagToList, isEmptyBag )
65 import Maybes           ( catMaybes, maybeToBool )
66 import FiniteMap        ( emptyFM, addToFM, addToFM_C, fmToList, FiniteMap )
67 import UniqFM           ( lookupUFM, listToUFM )
68 import UniqSet          ( uniqSetToList )
69 import Util             ( sortLt, mapAccumL )
70 import Outputable
71 \end{code}
72
73 We have a function @startIface@ to open the output file and put
74 (something like) ``interface Foo'' in it.  It gives back a handle
75 for subsequent additions to the interface file.
76
77 We then have one-function-per-block-of-interface-stuff, e.g.,
78 @ifaceExportList@ produces the @__exports__@ section; it appends
79 to the handle provided by @startIface@.
80
81 \begin{code}
82 startIface  :: Module
83             -> IO (Maybe Handle) -- Nothing <=> don't do an interface
84
85 ifaceMain   :: Maybe Handle
86             -> InterfaceDetails
87             -> IO ()
88
89
90 ifaceDecls :: Maybe Handle
91            -> [TyCon] -> [Class]
92            -> Bag InstInfo 
93            -> [Id]              -- Ids used at code-gen time; they have better pragma info!
94            -> [CoreBind]        -- In dependency order, later depend on earlier
95            -> IO ()
96
97 endIface    :: Maybe Handle -> IO ()
98 \end{code}
99
100 \begin{code}
101 startIface mod
102   = case opt_ProduceHi of
103       Nothing -> return Nothing -- not producing any .hi file
104       Just fn -> do
105         if_hdl <- openFile fn WriteMode
106         hPutStr if_hdl ("__interface " ++ moduleString mod ++ ' ':show (opt_HiVersion :: Int))
107         hPutStrLn if_hdl " where"
108         return (Just if_hdl)
109
110 endIface Nothing        = return ()
111 endIface (Just if_hdl)  = hPutStr if_hdl "\n" >> hClose if_hdl
112 \end{code}
113
114
115 \begin{code}
116 ifaceMain Nothing iface_stuff = return ()
117 ifaceMain (Just if_hdl)
118           (import_usages, ExportEnv avails fixities, instance_modules)
119   = do
120     ifaceImports                if_hdl import_usages
121     ifaceInstanceModules        if_hdl instance_modules
122     ifaceExports                if_hdl avails
123     ifaceFixities               if_hdl fixities
124     return ()
125
126 ifaceDecls Nothing tycons classes inst_info final_ids simplified = return ()
127 ifaceDecls (Just hdl)
128            tycons classes
129            inst_infos
130            final_ids binds
131   | null_decls = return ()               
132         --  You could have a module with just (re-)exports/instances in it
133   | otherwise
134   = ifaceClasses hdl classes                    >>
135     ifaceInstances hdl inst_infos               >>= \ needed_ids ->
136     ifaceTyCons hdl tycons                      >>
137     ifaceBinds hdl needed_ids final_ids binds   >>
138     return ()
139   where
140      null_decls = null binds      && 
141                   null tycons     &&
142                   null classes    && 
143                   isEmptyBag inst_infos
144 \end{code}
145
146 \begin{code}
147 ifaceImports if_hdl import_usages
148   = hPutCol if_hdl upp_uses (sortLt lt_imp_vers import_usages)
149   where
150     upp_uses (m, mv, whats_imported)
151       = ptext SLIT("import ") <>
152         hsep [pprModule m, pprModuleBoot m, int mv, dcolon,
153               upp_import_versions whats_imported
154         ] <> semi
155
156         -- Importing the whole module is indicated by an empty list
157     upp_import_versions Everything = empty
158
159         -- For imported versions we do print the version number
160     upp_import_versions (Specifically nvs)
161       = hsep [ hsep [ppr_unqual_name n, int v] | (n,v) <- sort_versions nvs ]
162
163 ifaceInstanceModules if_hdl [] = return ()
164 ifaceInstanceModules if_hdl imods
165   = let sorted = sortLt (<) imods
166         lines = map (\m -> ptext SLIT("__instimport ") <> pprModule m <>
167                            ptext SLIT(" ;")) sorted
168     in 
169     printForIface if_hdl (vcat lines) >>
170     hPutStr if_hdl "\n"
171
172 ifaceExports if_hdl [] = return ()
173 ifaceExports if_hdl avails
174   = hPutCol if_hdl do_one_module (fmToList export_fm)
175   where
176         -- Sort them into groups by module
177     export_fm :: FiniteMap Module [AvailInfo]
178     export_fm = foldr insert emptyFM avails
179
180     insert avail efm = addToFM_C (++) efm mod [avail] 
181                      where
182                        mod = nameModule (availName avail)
183
184         -- Print one module's worth of stuff
185     do_one_module :: (Module, [AvailInfo]) -> SDoc
186     do_one_module (mod_name, avails@(avail1:_))
187         = ptext SLIT("__export ") <>
188           hsep [pprModuleBoot (nameModule (availName avail1)), 
189                 pprModule mod_name,
190                 hsep (map upp_avail (sortLt lt_avail avails))
191           ] <> semi
192
193 ifaceFixities if_hdl [] = return ()
194 ifaceFixities if_hdl fixities 
195   = hPutCol if_hdl upp_fixity fixities
196 \end{code}                       
197
198 %************************************************************************
199 %*                                                                      *
200 \subsection{Instance declarations}
201 %*                                                                      *
202 %************************************************************************
203
204
205 \begin{code}                     
206 ifaceInstances :: Handle -> Bag InstInfo -> IO IdSet            -- The IdSet is the needed dfuns
207 ifaceInstances if_hdl inst_infos
208   | null togo_insts = return emptyVarSet                 
209   | otherwise       = hPutCol if_hdl pp_inst (sortLt lt_inst togo_insts) >>
210                       return needed_ids
211   where                          
212     togo_insts  = filter is_togo_inst (bagToList inst_infos)
213     needed_ids  = mkVarSet [dfun_id | InstInfo _ _ _ _ dfun_id _ _ _ <- togo_insts]
214     is_togo_inst (InstInfo _ _ _ _ dfun_id _ _ _) = isLocallyDefined dfun_id
215                                  
216     -------                      
217     lt_inst (InstInfo _ _ _ _ dfun_id1 _ _ _)
218             (InstInfo _ _ _ _ dfun_id2 _ _ _)
219       = getOccName dfun_id1 < getOccName dfun_id2
220         -- The dfuns are assigned names df1, df2, etc, in order of original textual
221         -- occurrence, and this makes as good a sort order as any
222
223     -------                      
224     pp_inst (InstInfo clas tvs tys theta dfun_id _ _ _)
225       = let                      
226                 -- The deNoteType is very important.   It removes all type
227                 -- synonyms from the instance type in interface files.
228                 -- That in turn makes sure that when reading in instance decls
229                 -- from interface files that the 'gating' mechanism works properly.
230                 -- Otherwise you could have
231                 --      type Tibble = T Int
232                 --      instance Foo Tibble where ...
233                 -- and this instance decl wouldn't get imported into a module
234                 -- that mentioned T but not Tibble.
235             forall_ty     = mkSigmaTy tvs theta (deNoteType (mkDictTy clas tys))
236             renumbered_ty = tidyTopType forall_ty
237         in                       
238         hcat [ptext SLIT("instance "), pprType renumbered_ty, 
239                     ptext SLIT(" = "), ppr_unqual_name dfun_id, semi]
240 \end{code}
241
242
243 %************************************************************************
244 %*                                                                      *
245 \subsection{Printing values}
246 %*                                                                      *
247 %************************************************************************
248
249 \begin{code}
250 ifaceId :: (Id -> IdInfo)               -- This function "knows" the extra info added
251                                         -- by the STG passes.  Sigh
252
253             -> IdSet                    -- Set of Ids that are needed by earlier interface
254                                         -- file emissions.  If the Id isn't in this set, and isn't
255                                         -- exported, there's no need to emit anything
256             -> Bool                     -- True <=> recursive, so don't print unfolding
257             -> Id
258             -> CoreExpr                 -- The Id's right hand side
259             -> Maybe (SDoc, IdSet)      -- The emitted stuff, plus a possibly-augmented set of needed Ids
260
261 ifaceId get_idinfo needed_ids is_rec id rhs
262   | not (id `elemVarSet` needed_ids ||          -- Needed [no id in needed_ids has omitIfaceSigForId]
263          (isExported id && not (omitIfaceSigForId id))) -- or exported and not to be omitted
264   = Nothing             -- Well, that was easy!
265
266 ifaceId get_idinfo needed_ids is_rec id rhs
267   = Just (hsep [sig_pretty, prag_pretty, char ';'], new_needed_ids)
268   where
269     idinfo         = get_idinfo id
270     inline_pragma  = inlinePragInfo idinfo
271
272     ty_pretty  = pprType (idType id)
273     sig_pretty = hsep [ppr (getOccName id), dcolon, ty_pretty]
274
275     prag_pretty 
276      | opt_OmitInterfacePragmas = empty
277      | otherwise                = hsep [ptext SLIT("{-##"),
278                                         arity_pretty, 
279                                         caf_pretty,
280                                         strict_pretty, 
281                                         unfold_pretty, 
282                                         spec_pretty,
283                                         ptext SLIT("##-}")]
284
285     ------------  Arity  --------------
286     arity_pretty  = ppArityInfo (arityInfo idinfo)
287
288     ------------ Caf Info --------------
289     caf_pretty = ppCafInfo (cafInfo idinfo)
290
291     ------------  Strictness  --------------
292     strict_info   = strictnessInfo idinfo
293     has_worker    = workerExists strict_info
294     bottoming_fn  = isBottomingStrictness strict_info
295     strict_pretty = ppStrictnessInfo strict_info <+> wrkr_pretty
296
297     wrkr_pretty | not has_worker = empty
298                 | null con_list  = ppr work_id
299                 | otherwise      = ppr work_id <+> 
300                                    braces (hsep (map ppr con_list))
301
302     (work_id, wrapper_cons) = getWorkerIdAndCons id rhs
303     con_list                = uniqSetToList wrapper_cons
304
305     ------------  Unfolding  --------------
306     unfold_pretty | show_unfold = unfold_herald <+> pprIfaceUnfolding rhs
307                   | otherwise   = empty
308
309     show_unfold = not has_worker        &&      -- Not unnecessary
310                   not bottoming_fn      &&      -- Not necessary
311                   unfolding_needed              -- Not dangerous
312
313     unfolding_needed =  case inline_pragma of
314                               IMustBeINLINEd    -> definitely_ok_to_unfold
315                               IWantToBeINLINEd  -> definitely_ok_to_unfold
316                               NoInlinePragInfo  -> rhs_is_small
317                               other             -> False
318
319
320     unfold_herald = case inline_pragma of
321                         NoInlinePragInfo -> ptext SLIT("__u")
322                         other            -> ppr inline_pragma
323
324     rhs_is_small = case calcUnfoldingGuidance opt_InterfaceUnfoldThreshold rhs of
325                         UnfoldNever -> False    -- Too big
326                         other       ->  definitely_ok_to_unfold -- Small enough
327
328     definitely_ok_to_unfold =  okToUnfoldInHiFile rhs
329
330     ------------  Specialisations --------------
331     spec_list = specEnvToList (getIdSpecialisation id)
332     spec_pretty = hsep (map pp_spec spec_list)
333     pp_spec (tyvars, tys, rhs) = hsep [ptext SLIT("__P"),
334                                        if null tyvars then ptext SLIT("[ ]")
335                                                       else brackets (interppSP tyvars),
336                                         -- The lexer interprets "[]" as a CONID.  Sigh.
337                                        hsep (map pprParendType tys),
338                                        ptext SLIT("="),
339                                        pprIfaceUnfolding rhs
340                                  ]
341     
342     ------------  Extra free Ids  --------------
343     new_needed_ids = (needed_ids `minusVarSet` unitVarSet id)   `unionVarSet` 
344                      extra_ids
345
346     extra_ids | opt_OmitInterfacePragmas = emptyVarSet
347               | otherwise                = worker_ids   `unionVarSet`
348                                            unfold_ids   `unionVarSet`
349                                            spec_ids
350
351     worker_ids | has_worker && interesting work_id = unitVarSet work_id
352                         -- Conceivably, the worker might come from
353                         -- another module
354                | otherwise                         = emptyVarSet
355
356     spec_ids = foldr add emptyVarSet spec_list
357              where
358                add (_, _, rhs) = unionVarSet (find_fvs rhs)
359
360     unfold_ids | show_unfold = find_fvs rhs
361                | otherwise   = emptyVarSet
362
363     find_fvs expr = free_vars
364                   where
365                     free_vars = exprSomeFreeVars interesting expr
366
367     interesting id = isId id && isLocallyDefined id &&
368                      not (omitIfaceSigForId id)
369 \end{code}
370
371 \begin{code}
372 ifaceBinds :: Handle
373            -> IdSet             -- These Ids are needed already
374            -> [Id]              -- Ids used at code-gen time; they have better pragma info!
375            -> [CoreBind]        -- In dependency order, later depend on earlier
376            -> IO ()
377
378 ifaceBinds hdl needed_ids final_ids binds
379   = mapIO (printForIface hdl) pretties >>
380     hPutStr hdl "\n"
381   where
382     final_id_map  = listToUFM [(id,id) | id <- final_ids]
383     get_idinfo id = case lookupUFM final_id_map id of
384                         Just id' -> idInfo id'
385                         Nothing  -> pprTrace "ifaceBinds not found:" (ppr id) $
386                                     idInfo id
387
388     pretties = go needed_ids (reverse binds)    -- Reverse so that later things will 
389                                                 -- provoke earlier ones to be emitted
390     go needed [] = if not (isEmptyVarSet needed) then
391                         pprTrace "ifaceBinds: free vars:" 
392                                   (sep (map ppr (varSetElems needed))) $
393                         []
394                    else
395                         []
396
397     go needed (NonRec id rhs : binds)
398         = case ifaceId get_idinfo needed False id rhs of
399                 Nothing                -> go needed binds
400                 Just (pretty, needed') -> pretty : go needed' binds
401
402         -- Recursive groups are a bit more of a pain.  We may only need one to
403         -- start with, but it may call out the next one, and so on.  So we
404         -- have to look for a fixed point.
405     go needed (Rec pairs : binds)
406         = pretties ++ go needed'' binds
407         where
408           (needed', pretties) = go_rec needed pairs
409           needed'' = needed' `minusVarSet` mkVarSet (map fst pairs)
410                 -- Later ones may spuriously cause earlier ones to be "needed" again
411
412     go_rec :: IdSet -> [(Id,CoreExpr)] -> (IdSet, [SDoc])
413     go_rec needed pairs
414         | null pretties = (needed, [])
415         | otherwise     = (final_needed, more_pretties ++ pretties)
416         where
417           reduced_pairs                 = [pair | (pair,Nothing) <- pairs `zip` maybes]
418           pretties                      = catMaybes maybes
419           (needed', maybes)             = mapAccumL do_one needed pairs
420           (final_needed, more_pretties) = go_rec needed' reduced_pairs
421
422           do_one needed (id,rhs) = case ifaceId get_idinfo needed True id rhs of
423                                         Nothing                -> (needed,  Nothing)
424                                         Just (pretty, needed') -> (needed', Just pretty)
425 \end{code}
426
427
428 %************************************************************************
429 %*                                                                      *
430 \subsection{Random small things}
431 %*                                                                      *
432 %************************************************************************
433
434 \begin{code}
435 ifaceTyCons hdl tycons   = hPutCol hdl upp_tycon (sortLt (<) (filter (for_iface_name . getName) tycons ))
436 ifaceClasses hdl classes = hPutCol hdl upp_class (sortLt (<) (filter (for_iface_name . getName) classes))
437
438 for_iface_name name = isLocallyDefined name && 
439                       not (isWiredInName name)
440
441 upp_tycon tycon = ifaceTyCon tycon
442 upp_class clas  = ifaceClass clas
443 \end{code}
444
445
446 \begin{code}
447 ifaceTyCon :: TyCon -> SDoc
448 ifaceTyCon tycon
449   | isSynTyCon tycon
450   = hsep [ ptext SLIT("type"),
451            ppr (getName tycon),
452            pprTyVarBndrs tyvars,
453            ptext SLIT("="),
454            ppr ty,
455            semi
456     ]
457   where
458     (tyvars, ty) = getSynTyConDefn tycon
459
460 ifaceTyCon tycon
461   | isAlgTyCon tycon
462   = hsep [ ptext keyword,
463            ppr_decl_context (tyConTheta tycon),
464            ppr (getName tycon),
465            pprTyVarBndrs (tyConTyVars tycon),
466            ptext SLIT("="),
467            hsep (punctuate (ptext SLIT(" | ")) (map ppr_con (tyConDataCons tycon))),
468            semi
469     ]
470   where
471     keyword | isNewTyCon tycon = SLIT("newtype")
472             | otherwise        = SLIT("data")
473
474     tyvars = tyConTyVars tycon
475
476     ppr_con data_con 
477         | null field_labels
478         = ASSERT( tycon == tycon1 && tyvars == tyvars1 )
479           hsep [  ppr_ex ex_tyvars ex_theta,
480                   ppr name,
481                   hsep (map ppr_arg_ty (strict_marks `zip` arg_tys))
482                 ]
483
484         | otherwise
485         = hsep [  ppr_ex ex_tyvars ex_theta,
486                   ppr name,
487                   braces $ hsep $ punctuate comma (map ppr_field (strict_marks `zip` field_labels))
488                 ]
489           where
490            (tyvars1, theta1, ex_tyvars, ex_theta, arg_tys, tycon1) = dataConSig data_con
491            field_labels   = dataConFieldLabels data_con
492            strict_marks   = dataConStrictMarks data_con
493            name           = getName            data_con
494
495     ppr_ex [] ex_theta = ASSERT( null ex_theta ) empty
496     ppr_ex ex_tvs ex_theta = ptext SLIT("__forall") <+> brackets (pprTyVarBndrs ex_tvs)
497                              <+> pprIfaceTheta ex_theta <+> ptext SLIT("=>")
498
499     ppr_arg_ty (strict_mark, ty) = ppr_strict_mark strict_mark <> pprParendType ty
500
501     ppr_strict_mark NotMarkedStrict        = empty
502     ppr_strict_mark (MarkedUnboxed _ _)    = ptext SLIT("! ! ")
503     ppr_strict_mark MarkedStrict           = ptext SLIT("! ")
504
505     ppr_field (strict_mark, field_label)
506         = hsep [ ppr (fieldLabelName field_label),
507                   dcolon,
508                   ppr_strict_mark strict_mark <> pprParendType (fieldLabelType field_label)
509                 ]
510
511 ifaceTyCon tycon
512   = pprPanic "pprIfaceTyDecl" (ppr tycon)
513
514 ifaceClass clas
515   = hsep [ptext SLIT("class"),
516            ppr_decl_context sc_theta,
517            ppr clas,                    -- Print the name
518            pprTyVarBndrs clas_tyvars,
519            pp_ops,
520            semi
521           ]
522    where
523      (clas_tyvars, sc_theta, _, sel_ids, defms) = classBigSig clas
524
525      pp_ops | null sel_ids  = empty
526             | otherwise = hsep [ptext SLIT("where"),
527                                  braces (hsep (punctuate semi (zipWith ppr_classop sel_ids defms)))
528                           ]
529
530      ppr_classop sel_id maybe_defm
531         = ASSERT( sel_tyvars == clas_tyvars)
532           hsep [ppr (getOccName sel_id),
533                 if maybeToBool maybe_defm then equals else empty,
534                 dcolon,
535                 ppr op_ty
536           ]
537         where
538           (sel_tyvars, _, op_ty) = splitSigmaTy (idType sel_id)
539
540 ppr_decl_context :: ThetaType -> SDoc
541 ppr_decl_context []    = empty
542 ppr_decl_context theta = pprIfaceTheta theta <+> ptext SLIT(" =>")
543
544 pprIfaceTheta :: ThetaType -> SDoc      -- Use braces rather than parens in interface files
545 pprIfaceTheta []    = empty
546 pprIfaceTheta theta = braces (hsep (punctuate comma [pprConstraint c tys | (c,tys) <- theta]))
547 \end{code}
548
549 %************************************************************************
550 %*                                                                      *
551 \subsection{Random small things}
552 %*                                                                      *
553 %************************************************************************
554
555 When printing export lists, we print like this:
556         Avail   f               f
557         AvailTC C [C, x, y]     C(x,y)
558         AvailTC C [x, y]        C!(x,y)         -- Exporting x, y but not C
559
560 \begin{code}
561 upp_avail :: AvailInfo -> SDoc
562 upp_avail (Avail name)      = pprOccName (getOccName name)
563 upp_avail (AvailTC name []) = empty
564 upp_avail (AvailTC name ns) = hcat [pprOccName (getOccName name), bang, upp_export ns']
565                             where
566                               bang | name `elem` ns = empty
567                                    | otherwise      = char '|'
568                               ns' = filter (/= name) ns
569
570 upp_export :: [Name] -> SDoc
571 upp_export []    = empty
572 upp_export names = braces (hsep (map (pprOccName . getOccName) names)) 
573
574 upp_fixity :: (Name, Fixity) -> SDoc
575 upp_fixity (name, fixity) = hsep [ptext SLIT("0"), ppr fixity, ppr name, semi]
576         -- Dummy version number!
577
578 ppr_unqual_name :: NamedThing a => a -> SDoc            -- Just its occurrence name
579 ppr_unqual_name name = pprOccName (getOccName name)
580 \end{code}
581
582
583 %************************************************************************
584 %*                                                                      *
585 \subsection{Comparisons
586 %*                                                                      *
587 %************************************************************************
588                                  
589
590 The various sorts above simply prevent unnecessary "wobbling" when
591 things change that don't have to.  We therefore compare lexically, not
592 by unique
593
594 \begin{code}
595 lt_avail :: AvailInfo -> AvailInfo -> Bool
596
597 a1 `lt_avail` a2 = availName a1 `lt_name` availName a2
598
599 lt_name :: Name -> Name -> Bool
600 n1 `lt_name` n2 = nameRdrName n1 < nameRdrName n2
601
602 lt_lexical :: NamedThing a => a -> a -> Bool
603 lt_lexical a1 a2 = getName a1 `lt_name` getName a2
604
605 lt_imp_vers :: ImportVersion a -> ImportVersion a -> Bool
606 lt_imp_vers (m1,_,_) (m2,_,_) = m1 < m2
607
608 sort_versions vs = sortLt lt_vers vs
609
610 lt_vers :: LocalVersion Name -> LocalVersion Name -> Bool
611 lt_vers (n1,v1) (n2,v2) = n1 `lt_name` n2
612 \end{code}
613
614
615 \begin{code}
616 hPutCol :: Handle 
617         -> (a -> SDoc)
618         -> [a]
619         -> IO ()
620 hPutCol hdl fmt xs = mapIO (printForIface hdl . fmt) xs
621
622 mapIO :: (a -> IO b) -> [a] -> IO ()
623 mapIO f []     = return ()
624 mapIO f (x:xs) = f x >> mapIO f xs
625 \end{code}