a3b148e0b96bba1ad5813c991fba89e80c2019e9
[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 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 RnHsSyn          ( RenamedHsModule )
21 import BasicTypes       ( Fixity(..), FixityDirection(..), NewOrData(..), IfaceFlavour(..),
22                           pprModule
23                         )
24 import RnMonad
25 import RnEnv            ( availName, ifaceFlavour )
26
27 import TcInstUtil       ( InstInfo(..) )
28 import WorkWrap         ( getWorkerIdAndCons )
29
30 import CmdLineOpts
31 import Id               ( idType, dataConRawArgTys, dataConFieldLabels, 
32                           idInfo, omitIfaceSigForId,
33                           dataConStrictMarks, StrictnessMark(..), 
34                           IdSet, idSetToList, unionIdSets, unitIdSet, minusIdSet, 
35                           isEmptyIdSet, elementOfIdSet, emptyIdSet, mkIdSet,
36                           pprId, getIdSpecialisation,
37                           Id
38                         )
39 import IdInfo           ( IdInfo, StrictnessInfo, ArityInfo, InlinePragInfo(..), inlinePragInfo,
40                           arityInfo, ppArityInfo, strictnessInfo, ppStrictnessInfo, 
41                           bottomIsGuaranteed, workerExists, 
42                         )
43 import CoreSyn          ( CoreExpr, CoreBinding, GenCoreExpr, GenCoreBinding(..) )
44 import CoreUnfold       ( calcUnfoldingGuidance, UnfoldingGuidance(..), Unfolding,
45                           okToUnfoldInHiFile
46                         )
47 import FreeVars         ( exprFreeVars )
48 import Name             ( isLocallyDefined, isWiredInName, modAndOcc, nameModule, pprOccName,
49                           OccName, occNameString, nameOccName, nameString, isExported,
50                           Name {-instance NamedThing-}, Provenance, NamedThing(..)
51                         )
52 import TyCon            ( TyCon, getSynTyConDefn, isSynTyCon, isNewTyCon, isAlgTyCon,
53                           tyConTheta, tyConTyVars, tyConDataCons
54                         )
55 import Class            ( Class, classBigSig )
56 import SpecEnv          ( specEnvToList )
57 import FieldLabel       ( fieldLabelName, fieldLabelType )
58 import Type             ( mkSigmaTy, splitSigmaTy, mkDictTy,
59                           mkTyVarTys, Type, ThetaType
60                         )
61
62 import PprEnv           -- not sure how much...
63 import PprType
64 import PprCore          ( pprIfaceUnfolding )
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 import Outputable
72 \end{code}
73
74 We have a function @startIface@ to open the output file and put
75 (something like) ``interface Foo'' in it.  It gives back a handle
76 for subsequent additions to the interface file.
77
78 We then have one-function-per-block-of-interface-stuff, e.g.,
79 @ifaceExportList@ produces the @__exports__@ section; it appends
80 to the handle provided by @startIface@.
81
82 \begin{code}
83 startIface  :: Module
84             -> IO (Maybe Handle) -- Nothing <=> don't do an interface
85
86 ifaceMain   :: Maybe Handle
87             -> InterfaceDetails
88             -> IO ()
89
90
91 ifaceDecls :: Maybe Handle
92            -> [TyCon] -> [Class]
93            -> Bag InstInfo 
94            -> [Id]              -- Ids used at code-gen time; they have better pragma info!
95            -> [CoreBinding]     -- In dependency order, later depend on earlier
96            -> IO ()
97
98 endIface    :: Maybe Handle -> IO ()
99 \end{code}
100
101 \begin{code}
102 startIface mod
103   = case opt_ProduceHi of
104       Nothing -> return Nothing -- not producing any .hi file
105       Just fn -> do
106         if_hdl <- openFile fn WriteMode
107         hPutStrLn if_hdl ("_interface_ "++ _UNPK_ mod ++ ' ':show (opt_HiVersion :: Int))
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   =
120     ifaceInstanceModules        if_hdl instance_modules         >>
121     ifaceUsages                 if_hdl import_usages            >>
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   = ifaceInstances hdl inst_infos               >>= \ needed_ids ->
135     hPutStr hdl "_declarations_\n"              >>
136     ifaceClasses hdl classes                    >>
137     ifaceTyCons hdl tycons                      >>
138     ifaceBinds hdl needed_ids final_ids binds   >>
139     return ()
140   where
141      null_decls = null binds      && 
142                   null tycons     &&
143                   null classes    && 
144                   isEmptyBag inst_infos
145 \end{code}
146
147 \begin{code}
148 ifaceUsages if_hdl import_usages
149   = hPutStr if_hdl "_usages_\n"   >>
150     hPutCol if_hdl upp_uses (sortLt lt_imp_vers import_usages)
151   where
152     upp_uses (m, hif, mv, whats_imported)
153       = hsep [pprModule m, pp_hif hif, int mv, ptext SLIT("::"),
154               upp_import_versions whats_imported
155         ] <> semi
156
157         -- Importing the whole module is indicated by an empty list
158     upp_import_versions Everything = empty
159
160         -- For imported versions we do print the version number
161     upp_import_versions (Specifically nvs)
162       = hsep [ hsep [ppr_unqual_name n, int v] | (n,v) <- sort_versions nvs ]
163
164 ifaceInstanceModules if_hdl [] = return ()
165 ifaceInstanceModules if_hdl imods
166   = hPutStr if_hdl "_instance_modules_\n" >>
167     printForIface 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 :: (Module, [AvailInfo]) -> SDoc
186     do_one_module (mod_name, avails@(avail1:_))
187         = hsep [pp_hif (ifaceFlavour (availName avail1)), 
188                 pprModule mod_name,
189                 hsep (map upp_avail (sortLt lt_avail avails))
190           ] <> semi
191
192 -- The "!" indicates that the exported things came from a hi-boot interface 
193 pp_hif HiFile     = empty
194 pp_hif HiBootFile = char '!'
195
196 ifaceFixities if_hdl [] = return ()
197 ifaceFixities if_hdl fixities 
198   = hPutStr if_hdl "_fixities_\n"               >>
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 emptyIdSet          
213   | otherwise       = hPutStr if_hdl "_instances_\n" >>
214                       hPutCol if_hdl pp_inst (sortLt lt_inst togo_insts) >>
215                       return needed_ids
216   where                          
217     togo_insts  = filter is_togo_inst (bagToList inst_infos)
218     needed_ids  = mkIdSet [dfun_id | InstInfo _ _ _ _ _ dfun_id _ _ _ <- togo_insts]
219     is_togo_inst (InstInfo _ _ _ _ _ dfun_id _ _ _) = isLocallyDefined dfun_id
220                                  
221     -------                      
222     lt_inst (InstInfo _ _ _ _ _ dfun_id1 _ _ _)
223             (InstInfo _ _ _ _ _ dfun_id2 _ _ _)
224       = getOccName dfun_id1 < getOccName dfun_id2
225         -- The dfuns are assigned names df1, df2, etc, in order of original textual
226         -- occurrence, and this makes as good a sort order as any
227
228     -------                      
229     pp_inst (InstInfo clas tvs tys theta _ dfun_id _ _ _)
230       = let                      
231             forall_ty     = mkSigmaTy tvs theta (mkDictTy clas tys)
232             renumbered_ty = nmbrGlobalType forall_ty
233         in                       
234         hcat [ptext SLIT("instance "), pprType renumbered_ty, 
235                     ptext SLIT(" = "), ppr_unqual_name dfun_id, semi]
236 \end{code}
237
238
239 %************************************************************************
240 %*                                                                      *
241 \subsection{Printing values}
242 %*                                                                      *
243 %************************************************************************
244
245 \begin{code}
246 ifaceId :: (Id -> IdInfo)               -- This function "knows" the extra info added
247                                         -- by the STG passes.  Sigh
248
249             -> IdSet                    -- Set of Ids that are needed by earlier interface
250                                         -- file emissions.  If the Id isn't in this set, and isn't
251                                         -- exported, there's no need to emit anything
252             -> Bool                     -- True <=> recursive, so don't print unfolding
253             -> Id
254             -> CoreExpr                 -- The Id's right hand side
255             -> Maybe (SDoc, IdSet)      -- The emitted stuff, plus a possibly-augmented set of needed Ids
256
257 ifaceId get_idinfo needed_ids is_rec id rhs
258   | not (id `elementOfIdSet` needed_ids ||              -- Needed [no id in needed_ids has omitIfaceSigForId]
259          (isExported id && not (omitIfaceSigForId id))) -- or exported and not to be omitted
260   = Nothing             -- Well, that was easy!
261
262 ifaceId get_idinfo needed_ids is_rec id rhs
263   = Just (hsep [sig_pretty, pp_double_semi, prag_pretty], new_needed_ids)
264   where
265     pp_double_semi = ptext SLIT(";;")
266     idinfo         = get_idinfo id
267     inline_pragma  = inlinePragInfo idinfo
268
269     ty_pretty  = pprType (nmbrGlobalType (idType id))
270     sig_pretty = hcat [ppr (getOccName id), ptext SLIT(" _:_ "), ty_pretty]
271
272     prag_pretty 
273      | opt_OmitInterfacePragmas = empty
274      | otherwise                = hsep [arity_pretty, strict_pretty, unfold_pretty, 
275                                         spec_pretty, pp_double_semi]
276
277     ------------  Arity  --------------
278     arity_pretty  = ppArityInfo (arityInfo idinfo)
279
280     ------------  Strictness  --------------
281     strict_info   = strictnessInfo idinfo
282     has_worker    = workerExists strict_info
283     strict_pretty = ppStrictnessInfo strict_info <+> wrkr_pretty
284
285     wrkr_pretty | not has_worker = empty
286                 | null con_list  = pprId work_id
287                 | otherwise      = pprId work_id <+> 
288                                    braces (hsep (map (pprId) con_list))
289
290     (work_id, wrapper_cons) = getWorkerIdAndCons id rhs
291     con_list               = idSetToList wrapper_cons
292
293     ------------  Unfolding  --------------
294     unfold_pretty | show_unfold = hsep [ptext unfold_herald, pprIfaceUnfolding rhs]
295                   | otherwise   = empty
296
297     unfold_herald = case inline_pragma of
298                         IMustBeINLINEd   -> SLIT("_U_")
299                         IWantToBeINLINEd -> SLIT("_U_")
300                         other            -> SLIT("_u_")
301
302     show_unfold = not implicit_unfolding &&     -- Not unnecessary
303                   unfolding_is_ok               -- Not dangerous
304
305     implicit_unfolding = has_worker ||
306                          bottomIsGuaranteed strict_info
307
308     unfolding_is_ok
309         = case inline_pragma of
310             IMustBeINLINEd       -> definitely_ok_to_unfold
311             IWantToBeINLINEd     -> definitely_ok_to_unfold
312             IDontWantToBeINLINEd -> False
313             IMustNotBeINLINEd    -> False
314             NoPragmaInfo         -> case guidance of
315                                         UnfoldNever -> False    -- Too big
316                                         other       -> definitely_ok_to_unfold
317
318     definitely_ok_to_unfold =  okToUnfoldInHiFile rhs
319     guidance = calcUnfoldingGuidance opt_InterfaceUnfoldThreshold rhs
320
321     ------------  Specialisations --------------
322     spec_list = specEnvToList (getIdSpecialisation id)
323     spec_pretty = hsep (map pp_spec spec_list)
324     pp_spec (tyvars, tys, rhs) = hsep [ptext SLIT("_P_"),
325                                        if null tyvars then ptext SLIT("[ ]")
326                                                       else brackets (interppSP tyvars),
327                                         -- The lexer interprets "[]" as a CONID.  Sigh.
328                                        hsep (map pprParendType tys),
329                                        ptext SLIT("="),
330                                        pprIfaceUnfolding rhs
331                                  ]
332     
333     ------------  Extra free Ids  --------------
334     new_needed_ids = (needed_ids `minusIdSet` unitIdSet id)     `unionIdSets` 
335                      extra_ids
336
337     extra_ids | opt_OmitInterfacePragmas = emptyIdSet
338               | otherwise                = worker_ids   `unionIdSets`
339                                            unfold_ids   `unionIdSets`
340                                            spec_ids
341
342     worker_ids | has_worker = unitIdSet work_id
343                | otherwise  = emptyIdSet
344
345     spec_ids = foldr add emptyIdSet spec_list
346              where
347                add (_, _, rhs) = unionIdSets (find_fvs rhs)
348
349     unfold_ids | show_unfold = find_fvs rhs
350                | otherwise   = emptyIdSet
351
352     find_fvs expr = free_vars
353                   where
354                     free_vars = exprFreeVars interesting expr
355                     interesting id = isLocallyDefined id &&
356                                      not (omitIfaceSigForId id)
357 \end{code}
358
359 \begin{code}
360 ifaceBinds :: Handle
361            -> IdSet             -- These Ids are needed already
362            -> [Id]              -- Ids used at code-gen time; they have better pragma info!
363            -> [CoreBinding]     -- In dependency order, later depend on earlier
364            -> IO ()
365
366 ifaceBinds hdl needed_ids final_ids binds
367   = mapIO (printForIface hdl) pretties >>
368     hPutStr hdl "\n"
369   where
370     final_id_map  = listToUFM [(id,id) | id <- final_ids]
371     get_idinfo id = case lookupUFM final_id_map id of
372                         Just id' -> idInfo id'
373                         Nothing  -> pprTrace "ifaceBinds not found:" (ppr id) $
374                                     idInfo id
375
376     pretties = go needed_ids (reverse binds)    -- Reverse so that later things will 
377                                                 -- provoke earlier ones to be emitted
378     go needed [] = if not (isEmptyIdSet needed) then
379                         pprTrace "ifaceBinds: free vars:" 
380                                   (sep (map ppr (idSetToList needed))) $
381                         []
382                    else
383                         []
384
385     go needed (NonRec id rhs : binds)
386         = case ifaceId get_idinfo needed False id rhs of
387                 Nothing                -> go needed binds
388                 Just (pretty, needed') -> pretty : go needed' binds
389
390         -- Recursive groups are a bit more of a pain.  We may only need one to
391         -- start with, but it may call out the next one, and so on.  So we
392         -- have to look for a fixed point.
393     go needed (Rec pairs : binds)
394         = pretties ++ go needed'' binds
395         where
396           (needed', pretties) = go_rec needed pairs
397           needed'' = needed' `minusIdSet` mkIdSet (map fst pairs)
398                 -- Later ones may spuriously cause earlier ones to be "needed" again
399
400     go_rec :: IdSet -> [(Id,CoreExpr)] -> (IdSet, [SDoc])
401     go_rec needed pairs
402         | null pretties = (needed, [])
403         | otherwise     = (final_needed, more_pretties ++ pretties)
404         where
405           reduced_pairs                 = [pair | (pair,Nothing) <- pairs `zip` maybes]
406           pretties                      = catMaybes maybes
407           (needed', maybes)             = mapAccumL do_one needed pairs
408           (final_needed, more_pretties) = go_rec needed' reduced_pairs
409
410           do_one needed (id,rhs) = case ifaceId get_idinfo needed True id rhs of
411                                         Nothing                -> (needed,  Nothing)
412                                         Just (pretty, needed') -> (needed', Just pretty)
413 \end{code}
414
415
416 %************************************************************************
417 %*                                                                      *
418 \subsection{Random small things}
419 %*                                                                      *
420 %************************************************************************
421
422 \begin{code}
423 ifaceTyCons hdl tycons   = hPutCol hdl upp_tycon (sortLt (<) (filter (for_iface_name . getName) tycons ))
424 ifaceClasses hdl classes = hPutCol hdl upp_class (sortLt (<) (filter (for_iface_name . getName) classes))
425
426 for_iface_name name = isLocallyDefined name && 
427                       not (isWiredInName name)
428
429 upp_tycon tycon = ifaceTyCon tycon
430 upp_class clas  = ifaceClass clas
431 \end{code}
432
433
434 \begin{code}
435 ifaceTyCon :: TyCon -> SDoc
436 ifaceTyCon tycon
437   | isSynTyCon tycon
438   = hsep [ ptext SLIT("type"),
439            ppr (getName tycon),
440            pprTyVarBndrs tyvars,
441            ptext SLIT("="),
442            ppr ty,
443            semi
444     ]
445   where
446     (tyvars, ty) = getSynTyConDefn tycon
447
448 ifaceTyCon tycon
449   | isAlgTyCon tycon
450   = hsep [ ptext keyword,
451            ppr_decl_context (tyConTheta tycon),
452            ppr (getName tycon),
453            pprTyVarBndrs (tyConTyVars tycon),
454            ptext SLIT("="),
455            hsep (punctuate (ptext SLIT(" | ")) (map ppr_con (tyConDataCons tycon))),
456            semi
457     ]
458   where
459     keyword | isNewTyCon tycon = SLIT("newtype")
460             | otherwise        = SLIT("data")
461
462     ppr_con data_con 
463         | null field_labels
464         = hsep [ ppr name,
465                   hsep (map ppr_arg_ty (strict_marks `zip` arg_tys))
466                 ]
467
468         | otherwise
469         = hsep [ ppr name,
470                   braces $ hsep $ punctuate comma (map ppr_field (strict_marks `zip` field_labels))
471                 ]
472           where
473            field_labels   = dataConFieldLabels data_con
474            arg_tys        = dataConRawArgTys   data_con
475            strict_marks   = dataConStrictMarks data_con
476            name           = getName            data_con
477
478     ppr_arg_ty (strict_mark, ty) = ppr_strict_mark strict_mark <> pprParendType ty
479
480     ppr_strict_mark NotMarkedStrict = empty
481     ppr_strict_mark MarkedStrict    = ptext SLIT("! ")
482                                 -- The extra space helps the lexical analyser that lexes
483                                 -- interface files; it doesn't make the rigid operator/identifier
484                                 -- distinction, so "!a" is a valid identifier so far as it is concerned
485
486     ppr_field (strict_mark, field_label)
487         = hsep [ ppr (fieldLabelName field_label),
488                   ptext SLIT("::"),
489                   ppr_strict_mark strict_mark <> pprParendType (fieldLabelType field_label)
490                 ]
491
492 ifaceTyCon tycon
493   = pprPanic "pprIfaceTyDecl" (ppr tycon)
494
495 ifaceClass clas
496   = hsep [ptext SLIT("class"),
497            ppr_decl_context sc_theta,
498            ppr clas,                    -- Print the name
499            pprTyVarBndrs clas_tyvars,
500            pp_ops,
501            semi
502           ]
503    where
504      (clas_tyvars, sc_theta, _, sel_ids, defms) = classBigSig clas
505
506      pp_ops | null sel_ids  = empty
507             | otherwise = hsep [ptext SLIT("where"),
508                                  braces (hsep (punctuate semi (zipWith ppr_classop sel_ids defms)))
509                           ]
510
511      ppr_classop sel_id maybe_defm
512         = ASSERT( sel_tyvars == clas_tyvars)
513           hsep [ppr (getOccName sel_id),
514                 if maybeToBool maybe_defm then equals else empty,
515                 ptext SLIT("::"),
516                 ppr op_ty
517           ]
518         where
519           (sel_tyvars, _, op_ty) = splitSigmaTy (idType sel_id)
520
521 ppr_decl_context :: ThetaType -> SDoc
522 ppr_decl_context [] = empty
523 ppr_decl_context theta
524   = braces (hsep (punctuate comma (map (ppr_dict) theta)))
525     <> 
526     ptext SLIT(" =>")
527   where
528     ppr_dict (clas,tys) = ppr clas <+> hsep (map pprParendType tys)
529 \end{code}
530
531 %************************************************************************
532 %*                                                                      *
533 \subsection{Random small things}
534 %*                                                                      *
535 %************************************************************************
536
537 When printing export lists, we print like this:
538         Avail   f               f
539         AvailTC C [C, x, y]     C(x,y)
540         AvailTC C [x, y]        C!(x,y)         -- Exporting x, y but not C
541
542 \begin{code}
543 upp_avail NotAvailable      = empty
544 upp_avail (Avail name)      = upp_occname (getOccName name)
545 upp_avail (AvailTC name []) = empty
546 upp_avail (AvailTC name ns) = hcat [upp_occname (getOccName name), bang, upp_export ns']
547                             where
548                               bang | name `elem` ns = empty
549                                    | otherwise      = char '|'
550                               ns' = filter (/= name) ns
551
552 upp_export []    = empty
553 upp_export names = parens (hsep (map (upp_occname . getOccName) names)) 
554
555 upp_fixity (occ, fixity) = hcat [ppr fixity, space, upp_occname occ, semi]
556
557 ppr_unqual_name :: NamedThing a => a -> SDoc            -- Just its occurrence name
558 ppr_unqual_name name = upp_occname (getOccName name)
559
560 upp_occname :: OccName -> SDoc
561 upp_occname occ = ptext (occNameString occ)
562 \end{code}
563
564
565 %************************************************************************
566 %*                                                                      *
567 \subsection{Comparisons
568 %*                                                                      *
569 %************************************************************************
570                                  
571
572 The various sorts above simply prevent unnecessary "wobbling" when
573 things change that don't have to.  We therefore compare lexically, not
574 by unique
575
576 \begin{code}
577 lt_avail :: AvailInfo -> AvailInfo -> Bool
578
579 a1 `lt_avail` a2 = availName a1 `lt_name` availName a2
580
581 lt_name :: Name -> Name -> Bool
582 n1 `lt_name` n2 = modAndOcc n1 < modAndOcc n2
583
584 lt_lexical :: NamedThing a => a -> a -> Bool
585 lt_lexical a1 a2 = getName a1 `lt_name` getName a2
586
587 lt_imp_vers :: ImportVersion a -> ImportVersion a -> Bool
588 lt_imp_vers (m1,_,_,_) (m2,_,_,_) = m1 < m2
589
590 sort_versions vs = sortLt lt_vers vs
591
592 lt_vers :: LocalVersion Name -> LocalVersion Name -> Bool
593 lt_vers (n1,v1) (n2,v2) = n1 `lt_name` n2
594 \end{code}
595
596
597 \begin{code}
598 hPutCol :: Handle 
599         -> (a -> SDoc)
600         -> [a]
601         -> IO ()
602 hPutCol hdl fmt xs = mapIO (printForIface hdl . fmt) xs
603
604 mapIO :: (a -> IO b) -> [a] -> IO ()
605 mapIO f []     = return ()
606 mapIO f (x:xs) = f x >> mapIO f xs
607 \end{code}