[project @ 1997-07-05 03:02:04 by sof]
[ghc-hetmet.git] / ghc / compiler / main / MkIface.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1996
3 %
4 \section[MkIface]{Print an interface for a module}
5
6 \begin{code}
7 #include "HsVersions.h"
8
9 module MkIface (
10         startIface, endIface,
11         ifaceMain,
12         ifaceDecls
13     ) where
14
15 IMP_Ubiq(){-uitous-}
16 IMPORT_1_3(IO(Handle,hPutStr,openFile,hClose,IOMode(..)))
17
18 import HsSyn
19 import RdrHsSyn         ( RdrName(..) )
20 import RnHsSyn          ( SYN_IE(RenamedHsModule) )
21 import BasicTypes       ( Fixity(..), FixityDirection(..), NewOrData(..), IfaceFlavour(..) )
22 import RnMonad
23 import RnEnv            ( availName, ifaceFlavour )
24
25 import TcInstUtil       ( InstInfo(..) )
26
27 import CmdLineOpts
28 import Id               ( idType, dataConRawArgTys, dataConFieldLabels, 
29                           getIdInfo, getInlinePragma, omitIfaceSigForId,
30                           dataConStrictMarks, StrictnessMark(..), 
31                           SYN_IE(IdSet), idSetToList, unionIdSets, unitIdSet, minusIdSet, 
32                           isEmptyIdSet, elementOfIdSet, emptyIdSet, mkIdSet, pprId,
33                           GenId{-instance NamedThing/Outputable-}, SYN_IE(Id)
34
35                         )
36 import IdInfo           ( StrictnessInfo, ArityInfo, 
37                           arityInfo, ppArityInfo, strictnessInfo, ppStrictnessInfo, 
38                           workerExists, bottomIsGuaranteed, IdInfo
39                         )
40 import CoreSyn          ( SYN_IE(CoreExpr), SYN_IE(CoreBinding), GenCoreExpr, GenCoreBinding(..) )
41 import CoreUnfold       ( calcUnfoldingGuidance, UnfoldingGuidance(..), Unfolding )
42 import FreeVars         ( addExprFVs )
43 import WorkWrap         ( getWorkerIdAndCons )
44 import Name             ( isLocallyDefined, isWiredInName, modAndOcc, nameModule, pprOccName,
45                           OccName, occNameString, nameOccName, nameString, isExported,
46                           Name {-instance NamedThing-}, Provenance, NamedThing(..)
47                         )
48 import TyCon            ( TyCon(..) {-instance NamedThing-} )
49 import Class            ( GenClass(..){-instance NamedThing-}, SYN_IE(Class), classBigSig )
50 import FieldLabel       ( FieldLabel{-instance NamedThing-}, 
51                           fieldLabelName, fieldLabelType )
52 import Type             ( mkSigmaTy, mkDictTy, getAppTyCon, splitSigmaTy,
53                           mkTyVarTy, SYN_IE(Type)
54                         )
55 import TyVar            ( GenTyVar {- instance Eq -} )
56 import Unique           ( Unique {- instance Eq -} )
57
58 import PprEnv           -- not sure how much...
59 import Outputable       ( PprStyle(..), Outputable(..) )
60 import PprType
61 import PprCore          ( pprIfaceUnfolding )
62 import Pretty
63 import Outputable       ( printDoc )
64
65
66 import Bag              ( bagToList, isEmptyBag )
67 import Maybes           ( catMaybes, maybeToBool )
68 import FiniteMap        ( emptyFM, addToFM, addToFM_C, lookupFM, fmToList, eltsFM, FiniteMap )
69 import UniqFM           ( UniqFM, lookupUFM, listToUFM )
70 import Util             ( sortLt, zipWithEqual, zipWith3Equal, mapAccumL,
71                           assertPanic, panic{-ToDo:rm-}, pprTrace,
72                           pprPanic 
73                         )
74 \end{code}
75
76 We have a function @startIface@ to open the output file and put
77 (something like) ``interface Foo'' in it.  It gives back a handle
78 for subsequent additions to the interface file.
79
80 We then have one-function-per-block-of-interface-stuff, e.g.,
81 @ifaceExportList@ produces the @__exports__@ section; it appends
82 to the handle provided by @startIface@.
83
84 \begin{code}
85 startIface  :: Module
86             -> IO (Maybe Handle) -- Nothing <=> don't do an interface
87
88 ifaceMain   :: Maybe Handle
89             -> InterfaceDetails
90             -> IO ()
91
92
93 ifaceDecls :: Maybe Handle
94            -> [TyCon] -> [Class]
95            -> Bag InstInfo 
96            -> [Id]              -- Ids used at code-gen time; they have better pragma info!
97            -> [CoreBinding]     -- In dependency order, later depend on earlier
98            -> IO ()
99
100 endIface    :: Maybe Handle -> IO ()
101 \end{code}
102
103 \begin{code}
104 startIface mod
105   = case opt_ProduceHi of
106       Nothing -> return Nothing -- not producing any .hi file
107       Just fn ->
108         openFile fn WriteMode   >>= \ if_hdl ->
109         hPutStr if_hdl ("{-# GHC_PRAGMA INTERFACE VERSION 20 #-}\n_interface_ "++ _UNPK_ mod ++ "\n") >>
110         return (Just if_hdl)
111
112 endIface Nothing        = return ()
113 endIface (Just if_hdl)  = hPutStr if_hdl "\n" >> hClose if_hdl
114 \end{code}
115
116
117 \begin{code}
118 ifaceMain Nothing iface_stuff = return ()
119 ifaceMain (Just if_hdl)
120           (import_usages, ExportEnv avails fixities, instance_modules)
121   =
122     ifaceInstanceModules        if_hdl instance_modules         >>
123     ifaceUsages                 if_hdl import_usages            >>
124     ifaceExports                if_hdl avails                   >>
125     ifaceFixities               if_hdl fixities                 >>
126     return ()
127
128 ifaceDecls Nothing tycons classes inst_info final_ids simplified = return ()
129 ifaceDecls (Just hdl)
130            tycons classes
131            inst_infos
132            final_ids binds
133   | null_decls = return ()               
134         --  You could have a module with just (re-)exports/instances in it
135   | otherwise
136   = ifaceInstances hdl inst_infos               >>= \ needed_ids ->
137     hPutStr hdl "_declarations_\n"              >>
138     ifaceClasses hdl classes                    >>
139     ifaceTyCons hdl tycons                      >>
140     ifaceBinds hdl needed_ids final_ids binds   >>
141     return ()
142   where
143      null_decls = null binds      && 
144                   null tycons     &&
145                   null classes    && 
146                   isEmptyBag inst_infos
147 \end{code}
148
149 \begin{code}
150 ifaceUsages if_hdl import_usages
151   = hPutStr if_hdl "_usages_\n"   >>
152     hPutCol if_hdl upp_uses (sortLt lt_imp_vers import_usages)
153   where
154     upp_uses (m, hif, mv, versions)
155       = hsep [upp_module m, pp_hif hif, int mv, ptext SLIT("::"),
156               upp_import_versions (sort_versions versions)
157         ] <> semi
158
159         -- For imported versions we do print the version number
160     upp_import_versions nvs
161       = hsep [ hsep [ppr_unqual_name n, int v] | (n,v) <- nvs ]
162
163
164 ifaceInstanceModules if_hdl [] = return ()
165 ifaceInstanceModules if_hdl imods
166   = hPutStr if_hdl "_instance_modules_\n" >>
167     printDoc OneLineMode if_hdl (hsep (map ptext (sortLt (<) imods))) >>
168     hPutStr if_hdl "\n"
169
170 ifaceExports if_hdl [] = return ()
171 ifaceExports if_hdl avails
172   = hPutStr if_hdl "_exports_\n"                        >>
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 (mod_name, avails@(avail1:_))
186         = hsep [pp_hif (ifaceFlavour (availName avail1)), 
187                 upp_module mod_name,
188                 hsep (map upp_avail (sortLt lt_avail avails))
189           ] <> semi
190
191 -- The "!" indicates that the exported things came from a hi-boot interface 
192 pp_hif HiFile     = empty
193 pp_hif HiBootFile = char '!'
194
195 ifaceFixities if_hdl [] = return ()
196 ifaceFixities if_hdl fixities 
197   = hPutStr if_hdl "_fixities_\n"               >>
198     hPutCol if_hdl upp_fixity fixities
199 \end{code}                       
200
201 %************************************************************************
202 %*                                                                      *
203 \subsection{Instance declarations}
204 %*                                                                      *
205 %************************************************************************
206
207
208 \begin{code}                     
209 ifaceInstances :: Handle -> Bag InstInfo -> IO IdSet            -- The IdSet is the needed dfuns
210 ifaceInstances if_hdl inst_infos
211   | null togo_insts = return emptyIdSet          
212   | otherwise       = hPutStr if_hdl "_instances_\n" >>
213                       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  = mkIdSet [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 ty theta _ dfun_id _ _ _)
229       = let                      
230             forall_ty     = mkSigmaTy tvs theta (mkDictTy clas ty)
231             renumbered_ty = nmbrGlobalType forall_ty
232         in                       
233         hcat [ptext SLIT("instance "), ppr_ty 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 (Doc, 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 `elementOfIdSet` 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, pp_double_semi, prag_pretty], new_needed_ids)
263   where
264     pp_double_semi = ptext SLIT(";;")
265     idinfo         = get_idinfo id
266     inline_pragma  = getInlinePragma id 
267
268     ty_pretty  = pprType PprInterface (nmbrGlobalType (idType id))
269     sig_pretty = hcat [ppr PprInterface (getOccName id), ptext SLIT(" _:_ "), ty_pretty]
270
271     prag_pretty 
272      | opt_OmitInterfacePragmas = empty
273      | otherwise                = hsep [arity_pretty, strict_pretty, unfold_pretty, pp_double_semi]
274
275     ------------  Arity  --------------
276     arity_pretty  = ppArityInfo PprInterface (arityInfo idinfo)
277
278     ------------  Strictness  --------------
279     strict_info   = strictnessInfo idinfo
280     has_worker    = workerExists strict_info
281     strict_pretty = ppStrictnessInfo PprInterface strict_info <+> wrkr_pretty
282
283     wrkr_pretty | not has_worker = empty
284                 | null con_list  = pprId PprInterface work_id
285                 | otherwise      = pprId PprInterface work_id <+> braces (hsep (map (pprId PprInterface) con_list))
286
287     (work_id, wrapper_cons) = getWorkerIdAndCons id rhs
288     con_list               = idSetToList wrapper_cons
289
290     ------------  Unfolding  --------------
291     unfold_pretty | show_unfold = hsep [ptext SLIT("_U_"), pprIfaceUnfolding rhs]
292                   | otherwise   = empty
293
294     show_unfold = not implicit_unfolding &&             -- Not unnecessary
295                   not dodgy_unfolding                   -- Not dangerous
296
297     implicit_unfolding = has_worker ||
298                          bottomIsGuaranteed strict_info
299
300     dodgy_unfolding = case guidance of                  -- True <=> too big to show, or the Inline pragma
301                         UnfoldNever -> True             -- says it shouldn't be inlined
302                         other       -> False
303
304     guidance    = calcUnfoldingGuidance inline_pragma
305                                         opt_InterfaceUnfoldThreshold
306                                         rhs
307
308     
309     ------------  Extra free Ids  --------------
310     new_needed_ids = (needed_ids `minusIdSet` unitIdSet id)     `unionIdSets` 
311                      extra_ids
312
313     extra_ids | opt_OmitInterfacePragmas = emptyIdSet
314               | otherwise                = worker_ids   `unionIdSets`
315                                            unfold_ids
316
317     worker_ids | has_worker = unitIdSet work_id
318                | otherwise  = emptyIdSet
319
320     unfold_ids | show_unfold = free_vars
321                | otherwise   = emptyIdSet
322                              where
323                                (_,free_vars) = addExprFVs interesting emptyIdSet rhs
324                                interesting bound id = isLocallyDefined id &&
325                                                       not (id `elementOfIdSet` bound) &&
326                                                       not (omitIfaceSigForId id)
327 \end{code}
328
329 \begin{code}
330 ifaceBinds :: Handle
331            -> IdSet             -- These Ids are needed already
332            -> [Id]              -- Ids used at code-gen time; they have better pragma info!
333            -> [CoreBinding]     -- In dependency order, later depend on earlier
334            -> IO ()
335
336 ifaceBinds hdl needed_ids final_ids binds
337   = mapIO (printDoc OneLineMode hdl) pretties >>
338     hPutStr hdl "\n"
339   where
340     final_id_map  = listToUFM [(id,id) | id <- final_ids]
341     get_idinfo id = case lookupUFM final_id_map id of
342                         Just id' -> getIdInfo id'
343                         Nothing  -> pprTrace "ifaceBinds not found:" (ppr PprDebug id) $
344                                     getIdInfo id
345
346     pretties = go needed_ids (reverse binds)    -- Reverse so that later things will 
347                                                 -- provoke earlier ones to be emitted
348     go needed [] = if not (isEmptyIdSet needed) then
349                         pprTrace "ifaceBinds: free vars:" 
350                                   (sep (map (ppr PprDebug) (idSetToList needed))) $
351                         []
352                    else
353                         []
354
355     go needed (NonRec id rhs : binds)
356         = case ifaceId get_idinfo needed False id rhs of
357                 Nothing                -> go needed binds
358                 Just (pretty, needed') -> pretty : go needed' binds
359
360         -- Recursive groups are a bit more of a pain.  We may only need one to
361         -- start with, but it may call out the next one, and so on.  So we
362         -- have to look for a fixed point.
363     go needed (Rec pairs : binds)
364         = pretties ++ go needed'' binds
365         where
366           (needed', pretties) = go_rec needed pairs
367           needed'' = needed' `minusIdSet` mkIdSet (map fst pairs)
368                 -- Later ones may spuriously cause earlier ones to be "needed" again
369
370     go_rec :: IdSet -> [(Id,CoreExpr)] -> (IdSet, [Doc])
371     go_rec needed pairs
372         | null pretties = (needed, [])
373         | otherwise     = (final_needed, more_pretties ++ pretties)
374         where
375           reduced_pairs                 = [pair | (pair,Nothing) <- pairs `zip` maybes]
376           pretties                      = catMaybes maybes
377           (needed', maybes)             = mapAccumL do_one needed pairs
378           (final_needed, more_pretties) = go_rec needed' reduced_pairs
379
380           do_one needed (id,rhs) = case ifaceId get_idinfo needed True id rhs of
381                                         Nothing                -> (needed,  Nothing)
382                                         Just (pretty, needed') -> (needed', Just pretty)
383 \end{code}
384
385
386 %************************************************************************
387 %*                                                                      *
388 \subsection{Random small things}
389 %*                                                                      *
390 %************************************************************************
391
392 \begin{code}
393 ifaceTyCons hdl tycons   = hPutCol hdl upp_tycon (sortLt (<) (filter (for_iface_name . getName) tycons ))
394 ifaceClasses hdl classes = hPutCol hdl upp_class (sortLt (<) (filter (for_iface_name . getName) classes))
395
396 for_iface_name name = isLocallyDefined name && 
397                       not (isWiredInName name)
398
399 upp_tycon tycon = ifaceTyCon PprInterface tycon
400 upp_class clas  = ifaceClass PprInterface clas
401 \end{code}
402
403
404 \begin{code}
405 ifaceTyCon :: PprStyle -> TyCon -> Doc  
406 ifaceTyCon sty tycon
407   = case tycon of
408         DataTyCon uniq name kind tyvars theta data_cons deriv new_or_data
409            -> hsep [    ptext (keyword new_or_data), 
410                         ppr_decl_context sty theta,
411                         ppr sty name,
412                         hsep (map (pprTyVarBndr sty) tyvars),
413                         ptext SLIT("="),
414                         hsep (punctuate (ptext SLIT(" | ")) (map ppr_con data_cons)),
415                         semi
416                     ]
417
418         SynTyCon uniq name kind arity tyvars ty
419            -> hsep [    ptext SLIT("type"),
420                         ppr sty name,
421                         hsep (map (pprTyVarBndr sty) tyvars),
422                         ptext SLIT("="),
423                         ppr sty ty,
424                         semi
425                     ]
426         other -> pprPanic "pprIfaceTyDecl" (ppr PprDebug tycon)
427   where
428     keyword NewType  = SLIT("newtype")
429     keyword DataType = SLIT("data")
430
431     ppr_con data_con 
432         | null field_labels
433         = hsep [ ppr sty name,
434                   hsep (map ppr_arg_ty (strict_marks `zip` arg_tys))
435                 ]
436
437         | otherwise
438         = hsep [ ppr sty name,
439                   braces $ hsep $ punctuate comma (map ppr_field (strict_marks `zip` field_labels))
440                 ]
441           where
442            field_labels   = dataConFieldLabels data_con
443            arg_tys        = dataConRawArgTys   data_con
444            strict_marks   = dataConStrictMarks data_con
445            name           = getName            data_con
446
447     ppr_arg_ty (strict_mark, ty) = ppr_strict_mark strict_mark <> pprParendType sty ty
448
449     ppr_strict_mark NotMarkedStrict = empty
450     ppr_strict_mark MarkedStrict    = ptext SLIT("! ")
451                                 -- The extra space helps the lexical analyser that lexes
452                                 -- interface files; it doesn't make the rigid operator/identifier
453                                 -- distinction, so "!a" is a valid identifier so far as it is concerned
454
455     ppr_field (strict_mark, field_label)
456         = hsep [ ppr sty (fieldLabelName field_label),
457                   ptext SLIT("::"),
458                   ppr_strict_mark strict_mark <> pprParendType sty (fieldLabelType field_label)
459                 ]
460
461 ifaceClass sty clas
462   = hsep [ptext SLIT("class"),
463            ppr_decl_context sty theta,
464            ppr sty clas,                        -- Print the name
465            pprTyVarBndr sty clas_tyvar,
466            pp_ops,
467            semi
468           ]
469    where
470      (clas_tyvar, super_classes, _, sel_ids, defms) = classBigSig clas
471      theta = super_classes `zip` repeat (mkTyVarTy clas_tyvar)
472
473      pp_ops | null sel_ids  = empty
474             | otherwise = hsep [ptext SLIT("where"),
475                                  braces (hsep (punctuate semi (zipWith ppr_classop sel_ids defms)))
476                           ]
477
478      ppr_classop sel_id maybe_defm
479         = ASSERT( sel_tyvars == [clas_tyvar])
480           hsep [ppr sty (getOccName sel_id),
481                 if maybeToBool maybe_defm then equals else empty,
482                 ptext SLIT("::"),
483                 ppr sty op_ty
484           ]
485         where
486           (sel_tyvars, _, op_ty) = splitSigmaTy (idType sel_id)
487
488 ppr_decl_context :: PprStyle -> [(Class,Type)] -> Doc
489 ppr_decl_context sty [] = empty
490 ppr_decl_context sty theta
491   = braces (hsep (punctuate comma (map (ppr_dict) theta)))
492     <> 
493     ptext SLIT(" =>")
494   where
495     ppr_dict (clas,ty) = hsep [ppr sty clas, ppr sty ty]
496 \end{code}
497
498 %************************************************************************
499 %*                                                                      *
500 \subsection{Random small things}
501 %*                                                                      *
502 %************************************************************************
503
504 When printing export lists, we print like this:
505         Avail   f               f
506         AvailTC C [C, x, y]     C(x,y)
507         AvailTC C [x, y]        C!(x,y)         -- Exporting x, y but not C
508
509 \begin{code}
510 upp_avail NotAvailable      = empty
511 upp_avail (Avail name)      = upp_occname (getOccName name)
512 upp_avail (AvailTC name []) = empty
513 upp_avail (AvailTC name ns) = hcat [upp_occname (getOccName name), bang, upp_export ns']
514                             where
515                               bang | name `elem` ns = empty
516                                    | otherwise      = char '|'
517                               ns' = filter (/= name) ns
518
519 upp_export []    = empty
520 upp_export names = parens (hsep (map (upp_occname . getOccName) names)) 
521
522 upp_fixity (occ, (Fixity prec dir, prov)) = hcat [upp_dir dir, space, 
523                                                         int prec, space, 
524                                                         upp_occname occ, semi]
525 upp_dir InfixR = ptext SLIT("infixr")
526 upp_dir InfixL = ptext SLIT("infixl")
527 upp_dir InfixN = ptext SLIT("infix")
528
529 ppr_unqual_name :: NamedThing a => a -> Doc             -- Just its occurrence name
530 ppr_unqual_name name = upp_occname (getOccName name)
531
532 ppr_name :: NamedThing a => a -> Doc            -- Its full name
533 ppr_name   n = ptext (nameString (getName n))
534
535 upp_occname :: OccName -> Doc
536 upp_occname occ = ptext (occNameString occ)
537
538 upp_module :: Module -> Doc
539 upp_module mod = ptext mod
540
541 uppSemid   x = ppr PprInterface x <> semi -- micro util
542
543 ppr_ty    ty = pprType PprInterface ty
544 ppr_tyvar tv = ppr PprInterface tv
545 ppr_tyvar_bndr tv = pprTyVarBndr PprInterface tv
546
547 ppr_decl decl = ppr PprInterface decl <> semi
548 \end{code}
549
550
551 %************************************************************************
552 %*                                                                      *
553 \subsection{Comparisons
554 %*                                                                      *
555 %************************************************************************
556                                  
557
558 The various sorts above simply prevent unnecessary "wobbling" when
559 things change that don't have to.  We therefore compare lexically, not
560 by unique
561
562 \begin{code}
563 lt_avail :: AvailInfo -> AvailInfo -> Bool
564
565 a1 `lt_avail` a2 = availName a1 `lt_name` availName a2
566
567 lt_name :: Name -> Name -> Bool
568 n1 `lt_name` n2 = modAndOcc n1 < modAndOcc n2
569
570 lt_lexical :: NamedThing a => a -> a -> Bool
571 lt_lexical a1 a2 = getName a1 `lt_name` getName a2
572
573 lt_imp_vers :: ImportVersion a -> ImportVersion a -> Bool
574 lt_imp_vers (m1,_,_,_) (m2,_,_,_) = m1 < m2
575
576 sort_versions vs = sortLt lt_vers vs
577
578 lt_vers :: LocalVersion Name -> LocalVersion Name -> Bool
579 lt_vers (n1,v1) (n2,v2) = n1 `lt_name` n2
580 \end{code}
581
582
583 \begin{code}
584 hPutCol :: Handle 
585         -> (a -> Doc)
586         -> [a]
587         -> IO ()
588 hPutCol hdl fmt xs = mapIO (printDoc OneLineMode hdl . fmt) xs
589
590 mapIO :: (a -> IO b) -> [a] -> IO ()
591 mapIO f []     = return ()
592 mapIO f (x:xs) = f x >> mapIO f xs
593 \end{code}