065ae63d643cd3f4eeadda8ecbce9a714107c114
[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 RdrHsSyn         ( RdrName(..) )
20 import BasicTypes       ( Fixity(..), FixityDirection(..), NewOrData(..), IfaceFlavour(..),
21                           StrictnessMark(..) 
22                         )
23 import RnMonad
24 import RnEnv            ( availName, ifaceFlavour )
25
26 import TcInstUtil       ( InstInfo(..) )
27 import WorkWrap         ( getWorkerIdAndCons )
28
29 import CmdLineOpts
30 import Id               ( Id, idType, idInfo, omitIfaceSigForId,
31                           getIdSpecialisation
32                         )
33 import Var              ( isId )
34 import VarSet
35 import DataCon          ( dataConSig, dataConFieldLabels, dataConStrictMarks )
36 import IdInfo           ( IdInfo, StrictnessInfo, ArityInfo, InlinePragInfo(..), inlinePragInfo,
37                           arityInfo, ppArityInfo, 
38                           strictnessInfo, ppStrictnessInfo, 
39                           cafInfo, ppCafInfo,
40                           workerExists, isBottomingStrictness
41                         )
42 import CoreSyn          ( CoreExpr, CoreBind, Bind(..) )
43 import CoreUtils        ( exprSomeFreeVars )
44 import CoreUnfold       ( calcUnfoldingGuidance, UnfoldingGuidance(..), 
45                           Unfolding, okToUnfoldInHiFile )
46 import Name             ( isLocallyDefined, isWiredInName, modAndOcc, nameModule,
47                           OccName, pprOccName, pprModule, isExported, moduleString,
48                           Name, NamedThing(..)
49                         )
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,
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, hif, mv, whats_imported)
150       = ptext SLIT("import ") <>
151         hsep [pprModule m, pp_hif hif, 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 NotAvailable efm = efm
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 [pp_hif (ifaceFlavour (availName avail1)), 
189                 pprModule mod_name,
190                 hsep (map upp_avail (sortLt lt_avail avails))
191           ] <> semi
192
193 -- The "!" indicates that the exported things came from a hi-boot interface 
194 pp_hif HiFile     = empty
195 pp_hif HiBootFile = char '!'
196
197 ifaceFixities if_hdl [] = return ()
198 ifaceFixities if_hdl fixities 
199   = hPutCol if_hdl upp_fixity fixities
200 \end{code}                       
201
202 %************************************************************************
203 %*                                                                      *
204 \subsection{Instance declarations}
205 %*                                                                      *
206 %************************************************************************
207
208
209 \begin{code}                     
210 ifaceInstances :: Handle -> Bag InstInfo -> IO IdSet            -- The IdSet is the needed dfuns
211 ifaceInstances if_hdl inst_infos
212   | null togo_insts = return emptyVarSet                 
213   | otherwise       = hPutCol if_hdl pp_inst (sortLt lt_inst togo_insts) >>
214                       return needed_ids
215   where                          
216     togo_insts  = filter is_togo_inst (bagToList inst_infos)
217     needed_ids  = mkVarSet [dfun_id | InstInfo _ _ _ _ dfun_id _ _ _ <- togo_insts]
218     is_togo_inst (InstInfo _ _ _ _ dfun_id _ _ _) = isLocallyDefined dfun_id
219                                  
220     -------                      
221     lt_inst (InstInfo _ _ _ _ dfun_id1 _ _ _)
222             (InstInfo _ _ _ _ dfun_id2 _ _ _)
223       = getOccName dfun_id1 < getOccName dfun_id2
224         -- The dfuns are assigned names df1, df2, etc, in order of original textual
225         -- occurrence, and this makes as good a sort order as any
226
227     -------                      
228     pp_inst (InstInfo clas tvs tys theta dfun_id _ _ _)
229       = let                      
230             forall_ty     = mkSigmaTy tvs theta (mkDictTy clas tys)
231             renumbered_ty = tidyTopType forall_ty
232         in                       
233         hcat [ptext SLIT("instance "), pprType renumbered_ty, 
234                     ptext SLIT(" = "), ppr_unqual_name dfun_id, semi]
235 \end{code}
236
237
238 %************************************************************************
239 %*                                                                      *
240 \subsection{Printing values}
241 %*                                                                      *
242 %************************************************************************
243
244 \begin{code}
245 ifaceId :: (Id -> IdInfo)               -- This function "knows" the extra info added
246                                         -- by the STG passes.  Sigh
247
248             -> IdSet                    -- Set of Ids that are needed by earlier interface
249                                         -- file emissions.  If the Id isn't in this set, and isn't
250                                         -- exported, there's no need to emit anything
251             -> Bool                     -- True <=> recursive, so don't print unfolding
252             -> Id
253             -> CoreExpr                 -- The Id's right hand side
254             -> Maybe (SDoc, IdSet)      -- The emitted stuff, plus a possibly-augmented set of needed Ids
255
256 ifaceId get_idinfo needed_ids is_rec id rhs
257   | not (id `elemVarSet` needed_ids ||          -- Needed [no id in needed_ids has omitIfaceSigForId]
258          (isExported id && not (omitIfaceSigForId id))) -- or exported and not to be omitted
259   = Nothing             -- Well, that was easy!
260
261 ifaceId get_idinfo needed_ids is_rec id rhs
262   = Just (hsep [sig_pretty, prag_pretty, char ';'], new_needed_ids)
263   where
264     idinfo         = get_idinfo id
265     inline_pragma  = inlinePragInfo idinfo
266
267     ty_pretty  = pprType (idType id)
268     sig_pretty = hsep [ppr (getOccName id), dcolon, ty_pretty]
269
270     prag_pretty 
271      | opt_OmitInterfacePragmas = empty
272      | otherwise                = hsep [ptext SLIT("{-##"),
273                                         arity_pretty, 
274                                         caf_pretty,
275                                         strict_pretty, 
276                                         unfold_pretty, 
277                                         spec_pretty,
278                                         ptext SLIT("##-}")]
279
280     ------------  Arity  --------------
281     arity_pretty  = ppArityInfo (arityInfo idinfo)
282
283     ------------ Caf Info --------------
284     caf_pretty = ppCafInfo (cafInfo idinfo)
285
286     ------------  Strictness  --------------
287     strict_info   = strictnessInfo idinfo
288     has_worker    = workerExists strict_info
289     bottoming_fn  = isBottomingStrictness strict_info
290     strict_pretty = ppStrictnessInfo strict_info <+> wrkr_pretty
291
292     wrkr_pretty | not has_worker = empty
293                 | null con_list  = ppr work_id
294                 | otherwise      = ppr work_id <+> 
295                                    braces (hsep (map ppr con_list))
296
297     (work_id, wrapper_cons) = getWorkerIdAndCons id rhs
298     con_list                = uniqSetToList wrapper_cons
299
300     ------------  Unfolding  --------------
301     unfold_pretty | show_unfold = unfold_herald <+> pprIfaceUnfolding rhs
302                   | otherwise   = empty
303
304     show_unfold = not has_worker        &&      -- Not unnecessary
305                   not bottoming_fn      &&      -- Not necessary
306                   unfolding_needed              -- Not dangerous
307
308     unfolding_needed =  case inline_pragma of
309                               IMustBeINLINEd    -> definitely_ok_to_unfold
310                               IWantToBeINLINEd  -> definitely_ok_to_unfold
311                               NoInlinePragInfo  -> rhs_is_small
312                               other             -> False
313
314
315     unfold_herald = case inline_pragma of
316                         NoInlinePragInfo -> ptext SLIT("__u")
317                         other            -> ppr inline_pragma
318
319     rhs_is_small = case calcUnfoldingGuidance opt_InterfaceUnfoldThreshold rhs of
320                         UnfoldNever -> False    -- Too big
321                         other       ->  definitely_ok_to_unfold -- Small enough
322
323     definitely_ok_to_unfold =  okToUnfoldInHiFile rhs
324
325     ------------  Specialisations --------------
326     spec_list = specEnvToList (getIdSpecialisation id)
327     spec_pretty = hsep (map pp_spec spec_list)
328     pp_spec (tyvars, tys, rhs) = hsep [ptext SLIT("__P"),
329                                        if null tyvars then ptext SLIT("[ ]")
330                                                       else brackets (interppSP tyvars),
331                                         -- The lexer interprets "[]" as a CONID.  Sigh.
332                                        hsep (map pprParendType tys),
333                                        ptext SLIT("="),
334                                        pprIfaceUnfolding rhs
335                                  ]
336     
337     ------------  Extra free Ids  --------------
338     new_needed_ids = (needed_ids `minusVarSet` unitVarSet id)   `unionVarSet` 
339                      extra_ids
340
341     extra_ids | opt_OmitInterfacePragmas = emptyVarSet
342               | otherwise                = worker_ids   `unionVarSet`
343                                            unfold_ids   `unionVarSet`
344                                            spec_ids
345
346     worker_ids | has_worker = unitVarSet work_id
347                | otherwise  = emptyVarSet
348
349     spec_ids = foldr add emptyVarSet spec_list
350              where
351                add (_, _, rhs) = unionVarSet (find_fvs rhs)
352
353     unfold_ids | show_unfold = find_fvs rhs
354                | otherwise   = emptyVarSet
355
356     find_fvs expr = free_vars
357                   where
358                     free_vars = exprSomeFreeVars interesting expr
359                     interesting id = isId id && isLocallyDefined id &&
360                                      not (omitIfaceSigForId id)
361 \end{code}
362
363 \begin{code}
364 ifaceBinds :: Handle
365            -> IdSet             -- These Ids are needed already
366            -> [Id]              -- Ids used at code-gen time; they have better pragma info!
367            -> [CoreBind]        -- In dependency order, later depend on earlier
368            -> IO ()
369
370 ifaceBinds hdl needed_ids final_ids binds
371   = mapIO (printForIface hdl) pretties >>
372     hPutStr hdl "\n"
373   where
374     final_id_map  = listToUFM [(id,id) | id <- final_ids]
375     get_idinfo id = case lookupUFM final_id_map id of
376                         Just id' -> idInfo id'
377                         Nothing  -> pprTrace "ifaceBinds not found:" (ppr id) $
378                                     idInfo id
379
380     pretties = go needed_ids (reverse binds)    -- Reverse so that later things will 
381                                                 -- provoke earlier ones to be emitted
382     go needed [] = if not (isEmptyVarSet needed) then
383                         pprTrace "ifaceBinds: free vars:" 
384                                   (sep (map ppr (varSetElems needed))) $
385                         []
386                    else
387                         []
388
389     go needed (NonRec id rhs : binds)
390         = case ifaceId get_idinfo needed False id rhs of
391                 Nothing                -> go needed binds
392                 Just (pretty, needed') -> pretty : go needed' binds
393
394         -- Recursive groups are a bit more of a pain.  We may only need one to
395         -- start with, but it may call out the next one, and so on.  So we
396         -- have to look for a fixed point.
397     go needed (Rec pairs : binds)
398         = pretties ++ go needed'' binds
399         where
400           (needed', pretties) = go_rec needed pairs
401           needed'' = needed' `minusVarSet` mkVarSet (map fst pairs)
402                 -- Later ones may spuriously cause earlier ones to be "needed" again
403
404     go_rec :: IdSet -> [(Id,CoreExpr)] -> (IdSet, [SDoc])
405     go_rec needed pairs
406         | null pretties = (needed, [])
407         | otherwise     = (final_needed, more_pretties ++ pretties)
408         where
409           reduced_pairs                 = [pair | (pair,Nothing) <- pairs `zip` maybes]
410           pretties                      = catMaybes maybes
411           (needed', maybes)             = mapAccumL do_one needed pairs
412           (final_needed, more_pretties) = go_rec needed' reduced_pairs
413
414           do_one needed (id,rhs) = case ifaceId get_idinfo needed True id rhs of
415                                         Nothing                -> (needed,  Nothing)
416                                         Just (pretty, needed') -> (needed', Just pretty)
417 \end{code}
418
419
420 %************************************************************************
421 %*                                                                      *
422 \subsection{Random small things}
423 %*                                                                      *
424 %************************************************************************
425
426 \begin{code}
427 ifaceTyCons hdl tycons   = hPutCol hdl upp_tycon (sortLt (<) (filter (for_iface_name . getName) tycons ))
428 ifaceClasses hdl classes = hPutCol hdl upp_class (sortLt (<) (filter (for_iface_name . getName) classes))
429
430 for_iface_name name = isLocallyDefined name && 
431                       not (isWiredInName name)
432
433 upp_tycon tycon = ifaceTyCon tycon
434 upp_class clas  = ifaceClass clas
435 \end{code}
436
437
438 \begin{code}
439 ifaceTyCon :: TyCon -> SDoc
440 ifaceTyCon tycon
441   | isSynTyCon tycon
442   = hsep [ ptext SLIT("type"),
443            ppr (getName tycon),
444            pprTyVarBndrs tyvars,
445            ptext SLIT("="),
446            ppr ty,
447            semi
448     ]
449   where
450     (tyvars, ty) = getSynTyConDefn tycon
451
452 ifaceTyCon tycon
453   | isAlgTyCon tycon
454   = hsep [ ptext keyword,
455            ppr_decl_context (tyConTheta tycon),
456            ppr (getName tycon),
457            pprTyVarBndrs (tyConTyVars tycon),
458            ptext SLIT("="),
459            hsep (punctuate (ptext SLIT(" | ")) (map ppr_con (tyConDataCons tycon))),
460            semi
461     ]
462   where
463     keyword | isNewTyCon tycon = SLIT("newtype")
464             | otherwise        = SLIT("data")
465
466     tyvars = tyConTyVars tycon
467
468     ppr_con data_con 
469         | null field_labels
470         = ASSERT( tycon == tycon1 && tyvars == tyvars1 )
471           hsep [  ppr_ex ex_tyvars ex_theta,
472                   ppr name,
473                   hsep (map ppr_arg_ty (strict_marks `zip` arg_tys))
474                 ]
475
476         | otherwise
477         = hsep [  ppr_ex ex_tyvars ex_theta,
478                   ppr name,
479                   braces $ hsep $ punctuate comma (map ppr_field (strict_marks `zip` field_labels))
480                 ]
481           where
482            (tyvars1, theta1, ex_tyvars, ex_theta, arg_tys, tycon1) = dataConSig data_con
483            field_labels   = dataConFieldLabels data_con
484            strict_marks   = dataConStrictMarks data_con
485            name           = getName            data_con
486
487     ppr_ex [] ex_theta = ASSERT( null ex_theta ) empty
488     ppr_ex ex_tvs ex_theta = ptext SLIT("__forall") <+> brackets (pprTyVarBndrs ex_tvs)
489                              <+> pprIfaceTheta ex_theta <+> ptext SLIT("=>")
490
491     ppr_arg_ty (strict_mark, ty) = ppr_strict_mark strict_mark <> pprParendType ty
492
493     ppr_strict_mark NotMarkedStrict = empty
494     ppr_strict_mark MarkedStrict    = ptext SLIT("! ")
495                                 -- The extra space helps the lexical analyser that lexes
496                                 -- interface files; it doesn't make the rigid operator/identifier
497                                 -- distinction, so "!a" is a valid identifier so far as it is concerned
498
499     ppr_field (strict_mark, field_label)
500         = hsep [ ppr (fieldLabelName field_label),
501                   dcolon,
502                   ppr_strict_mark strict_mark <> pprParendType (fieldLabelType field_label)
503                 ]
504
505 ifaceTyCon tycon
506   = pprPanic "pprIfaceTyDecl" (ppr tycon)
507
508 ifaceClass clas
509   = hsep [ptext SLIT("class"),
510            ppr_decl_context sc_theta,
511            ppr clas,                    -- Print the name
512            pprTyVarBndrs clas_tyvars,
513            pp_ops,
514            semi
515           ]
516    where
517      (clas_tyvars, sc_theta, _, sel_ids, defms) = classBigSig clas
518
519      pp_ops | null sel_ids  = empty
520             | otherwise = hsep [ptext SLIT("where"),
521                                  braces (hsep (punctuate semi (zipWith ppr_classop sel_ids defms)))
522                           ]
523
524      ppr_classop sel_id maybe_defm
525         = ASSERT( sel_tyvars == clas_tyvars)
526           hsep [ppr (getOccName sel_id),
527                 if maybeToBool maybe_defm then equals else empty,
528                 dcolon,
529                 ppr op_ty
530           ]
531         where
532           (sel_tyvars, _, op_ty) = splitSigmaTy (idType sel_id)
533
534 ppr_decl_context :: ThetaType -> SDoc
535 ppr_decl_context []    = empty
536 ppr_decl_context theta = pprIfaceTheta theta <+> ptext SLIT(" =>")
537
538 pprIfaceTheta :: ThetaType -> SDoc      -- Use braces rather than parens in interface files
539 pprIfaceTheta theta =  braces (hsep (punctuate comma [pprConstraint c tys | (c,tys) <- theta]))
540 \end{code}
541
542 %************************************************************************
543 %*                                                                      *
544 \subsection{Random small things}
545 %*                                                                      *
546 %************************************************************************
547
548 When printing export lists, we print like this:
549         Avail   f               f
550         AvailTC C [C, x, y]     C(x,y)
551         AvailTC C [x, y]        C!(x,y)         -- Exporting x, y but not C
552
553 \begin{code}
554 upp_avail :: AvailInfo -> SDoc
555 upp_avail NotAvailable      = empty
556 upp_avail (Avail name)      = pprOccName (getOccName name)
557 upp_avail (AvailTC name []) = empty
558 upp_avail (AvailTC name ns) = hcat [pprOccName (getOccName name), bang, upp_export ns']
559                             where
560                               bang | name `elem` ns = empty
561                                    | otherwise      = char '|'
562                               ns' = filter (/= name) ns
563
564 upp_export :: [Name] -> SDoc
565 upp_export []    = empty
566 upp_export names = braces (hsep (map (pprOccName . getOccName) names)) 
567
568 upp_fixity :: (Name, Fixity) -> SDoc
569 upp_fixity (name, fixity) = hsep [ptext SLIT("0"), ppr fixity, ppr name, semi]
570         -- Dummy version number!
571
572 ppr_unqual_name :: NamedThing a => a -> SDoc            -- Just its occurrence name
573 ppr_unqual_name name = pprOccName (getOccName name)
574 \end{code}
575
576
577 %************************************************************************
578 %*                                                                      *
579 \subsection{Comparisons
580 %*                                                                      *
581 %************************************************************************
582                                  
583
584 The various sorts above simply prevent unnecessary "wobbling" when
585 things change that don't have to.  We therefore compare lexically, not
586 by unique
587
588 \begin{code}
589 lt_avail :: AvailInfo -> AvailInfo -> Bool
590
591 a1 `lt_avail` a2 = availName a1 `lt_name` availName a2
592
593 lt_name :: Name -> Name -> Bool
594 n1 `lt_name` n2 = modAndOcc n1 < modAndOcc n2
595
596 lt_lexical :: NamedThing a => a -> a -> Bool
597 lt_lexical a1 a2 = getName a1 `lt_name` getName a2
598
599 lt_imp_vers :: ImportVersion a -> ImportVersion a -> Bool
600 lt_imp_vers (m1,_,_,_) (m2,_,_,_) = m1 < m2
601
602 sort_versions vs = sortLt lt_vers vs
603
604 lt_vers :: LocalVersion Name -> LocalVersion Name -> Bool
605 lt_vers (n1,v1) (n2,v2) = n1 `lt_name` n2
606 \end{code}
607
608
609 \begin{code}
610 hPutCol :: Handle 
611         -> (a -> SDoc)
612         -> [a]
613         -> IO ()
614 hPutCol hdl fmt xs = mapIO (printForIface hdl . fmt) xs
615
616 mapIO :: (a -> IO b) -> [a] -> IO ()
617 mapIO f []     = return ()
618 mapIO f (x:xs) = f x >> mapIO f xs
619 \end{code}