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