[project @ 1998-04-08 16:48:14 by simonpj]
[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 import FreeVars         ( addExprFVs )
46 import Name             ( isLocallyDefined, isWiredInName, modAndOcc, nameModule, pprOccName,
47                           OccName, occNameString, nameOccName, nameString, isExported,
48                           Name {-instance NamedThing-}, Provenance, 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,
57                           mkTyVarTys, Type, ThetaType
58                         )
59
60 import PprEnv           -- not sure how much...
61 import PprType
62 import PprCore          ( pprIfaceUnfolding )
63
64 import Bag              ( bagToList, isEmptyBag )
65 import Maybes           ( catMaybes, maybeToBool )
66 import FiniteMap        ( emptyFM, addToFM, addToFM_C, lookupFM, fmToList, eltsFM, FiniteMap )
67 import UniqFM           ( UniqFM, lookupUFM, listToUFM )
68 import Util             ( sortLt, zipWithEqual, zipWith3Equal, 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            -> [CoreBinding]     -- 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         hPutStrLn if_hdl ("_interface_ "++ _UNPK_ mod ++ ' ':show (PROJECTVERSION :: Int))
106         return (Just if_hdl)
107
108 endIface Nothing        = return ()
109 endIface (Just if_hdl)  = hPutStr if_hdl "\n" >> hClose if_hdl
110 \end{code}
111
112
113 \begin{code}
114 ifaceMain Nothing iface_stuff = return ()
115 ifaceMain (Just if_hdl)
116           (import_usages, ExportEnv avails fixities, instance_modules)
117   =
118     ifaceInstanceModules        if_hdl instance_modules         >>
119     ifaceUsages                 if_hdl import_usages            >>
120     ifaceExports                if_hdl avails                   >>
121     ifaceFixities               if_hdl fixities                 >>
122     return ()
123
124 ifaceDecls Nothing tycons classes inst_info final_ids simplified = return ()
125 ifaceDecls (Just hdl)
126            tycons classes
127            inst_infos
128            final_ids binds
129   | null_decls = return ()               
130         --  You could have a module with just (re-)exports/instances in it
131   | otherwise
132   = ifaceInstances hdl inst_infos               >>= \ needed_ids ->
133     hPutStr hdl "_declarations_\n"              >>
134     ifaceClasses hdl classes                    >>
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 ifaceUsages if_hdl import_usages
147   = hPutStr if_hdl "_usages_\n"   >>
148     hPutCol if_hdl upp_uses (sortLt lt_imp_vers import_usages)
149   where
150     upp_uses (m, hif, mv, whats_imported)
151       = hsep [pprModule m, pp_hif hif, int mv, ptext SLIT("::"),
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   = hPutStr if_hdl "_instance_modules_\n" >>
165     printForIface if_hdl (hsep (map ptext (sortLt (<) imods))) >>
166     hPutStr if_hdl "\n"
167
168 ifaceExports if_hdl [] = return ()
169 ifaceExports if_hdl avails
170   = hPutStr if_hdl "_exports_\n"                        >>
171     hPutCol if_hdl do_one_module (fmToList export_fm)
172   where
173         -- Sort them into groups by module
174     export_fm :: FiniteMap Module [AvailInfo]
175     export_fm = foldr insert emptyFM avails
176
177     insert NotAvailable efm = efm
178     insert avail efm = addToFM_C (++) efm mod [avail] 
179                      where
180                        mod = nameModule (availName avail)
181
182         -- Print one module's worth of stuff
183     do_one_module (mod_name, avails@(avail1:_))
184         = hsep [pp_hif (ifaceFlavour (availName avail1)), 
185                 pprModule mod_name,
186                 hsep (map upp_avail (sortLt lt_avail avails))
187           ] <> semi
188
189 -- The "!" indicates that the exported things came from a hi-boot interface 
190 pp_hif HiFile     = empty
191 pp_hif HiBootFile = char '!'
192
193 ifaceFixities if_hdl [] = return ()
194 ifaceFixities if_hdl fixities 
195   = hPutStr if_hdl "_fixities_\n"               >>
196     hPutCol if_hdl upp_fixity fixities
197 \end{code}                       
198
199 %************************************************************************
200 %*                                                                      *
201 \subsection{Instance declarations}
202 %*                                                                      *
203 %************************************************************************
204
205
206 \begin{code}                     
207 ifaceInstances :: Handle -> Bag InstInfo -> IO IdSet            -- The IdSet is the needed dfuns
208 ifaceInstances if_hdl inst_infos
209   | null togo_insts = return emptyIdSet          
210   | otherwise       = hPutStr if_hdl "_instances_\n" >>
211                       hPutCol if_hdl pp_inst (sortLt lt_inst togo_insts) >>
212                       return needed_ids
213   where                          
214     togo_insts  = filter is_togo_inst (bagToList inst_infos)
215     needed_ids  = mkIdSet [dfun_id | InstInfo _ _ _ _ _ dfun_id _ _ _ <- togo_insts]
216     is_togo_inst (InstInfo _ _ _ _ _ dfun_id _ _ _) = isLocallyDefined dfun_id
217                                  
218     -------                      
219     lt_inst (InstInfo _ _ _ _ _ dfun_id1 _ _ _)
220             (InstInfo _ _ _ _ _ dfun_id2 _ _ _)
221       = getOccName dfun_id1 < getOccName dfun_id2
222         -- The dfuns are assigned names df1, df2, etc, in order of original textual
223         -- occurrence, and this makes as good a sort order as any
224
225     -------                      
226     pp_inst (InstInfo clas tvs tys theta _ dfun_id _ _ _)
227       = let                      
228             forall_ty     = mkSigmaTy tvs theta (mkDictTy clas tys)
229             renumbered_ty = nmbrGlobalType forall_ty
230         in                       
231         hcat [ptext SLIT("instance "), pprType renumbered_ty, 
232                     ptext SLIT(" = "), ppr_unqual_name dfun_id, semi]
233 \end{code}
234
235
236 %************************************************************************
237 %*                                                                      *
238 \subsection{Printing values}
239 %*                                                                      *
240 %************************************************************************
241
242 \begin{code}
243 ifaceId :: (Id -> IdInfo)               -- This function "knows" the extra info added
244                                         -- by the STG passes.  Sigh
245
246             -> IdSet                    -- Set of Ids that are needed by earlier interface
247                                         -- file emissions.  If the Id isn't in this set, and isn't
248                                         -- exported, there's no need to emit anything
249             -> Bool                     -- True <=> recursive, so don't print unfolding
250             -> Id
251             -> CoreExpr                 -- The Id's right hand side
252             -> Maybe (SDoc, IdSet)      -- The emitted stuff, plus a possibly-augmented set of needed Ids
253
254 ifaceId get_idinfo needed_ids is_rec id rhs
255   | not (id `elementOfIdSet` needed_ids ||              -- Needed [no id in needed_ids has omitIfaceSigForId]
256          (isExported id && not (omitIfaceSigForId id))) -- or exported and not to be omitted
257   = Nothing             -- Well, that was easy!
258
259 ifaceId get_idinfo needed_ids is_rec id rhs
260   = Just (hsep [sig_pretty, pp_double_semi, prag_pretty], new_needed_ids)
261   where
262     pp_double_semi = ptext SLIT(";;")
263     idinfo         = get_idinfo id
264     inline_pragma  = inlinePragInfo idinfo
265
266     ty_pretty  = pprType (nmbrGlobalType (idType id))
267     sig_pretty = hcat [ppr (getOccName id), ptext SLIT(" _:_ "), ty_pretty]
268
269     prag_pretty 
270      | opt_OmitInterfacePragmas = empty
271      | otherwise                = hsep [arity_pretty, strict_pretty, unfold_pretty, 
272                                         spec_pretty, pp_double_semi]
273
274     ------------  Arity  --------------
275     arity_pretty  = ppArityInfo (arityInfo idinfo)
276
277     ------------  Strictness  --------------
278     strict_info   = strictnessInfo idinfo
279     has_worker    = workerExists strict_info
280     strict_pretty = ppStrictnessInfo strict_info <+> wrkr_pretty
281
282     wrkr_pretty | not has_worker = empty
283                 | null con_list  = pprId work_id
284                 | otherwise      = pprId work_id <+> 
285                                    braces (hsep (map (pprId) 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 unfold_herald, pprIfaceUnfolding rhs]
292                   | otherwise   = empty
293
294     unfold_herald = case inline_pragma of
295                         IMustBeINLINEd   -> SLIT("_U_")
296                         IWantToBeINLINEd -> SLIT("_U_")
297                         other            -> SLIT("_u_")
298
299     show_unfold = not implicit_unfolding &&     -- Not unnecessary
300                   unfolding_is_ok               -- Not dangerous
301
302     implicit_unfolding = has_worker ||
303                          bottomIsGuaranteed strict_info
304
305     unfolding_is_ok
306         = case inline_pragma of
307             IMustBeINLINEd    -> True
308             IWantToBeINLINEd  -> True
309             IMustNotBeINLINEd -> False
310             NoPragmaInfo      -> case guidance of
311                                         UnfoldNever -> False    -- Too big
312                                         other       -> True
313
314     guidance = calcUnfoldingGuidance opt_InterfaceUnfoldThreshold rhs
315
316     ------------  Specialisations --------------
317     spec_list = specEnvToList (getIdSpecialisation id)
318     spec_pretty = hsep (map pp_spec spec_list)
319     pp_spec (tyvars, tys, rhs) = hsep [ptext SLIT("_P_"),
320                                        if null tyvars then ptext SLIT("[ ]")
321                                                       else brackets (interppSP tyvars),
322                                         -- The lexer interprets "[]" as a CONID.  Sigh.
323                                        hsep (map pprParendType tys),
324                                        ptext SLIT("="),
325                                        pprIfaceUnfolding rhs
326                                  ]
327     
328     ------------  Extra free Ids  --------------
329     new_needed_ids = (needed_ids `minusIdSet` unitIdSet id)     `unionIdSets` 
330                      extra_ids
331
332     extra_ids | opt_OmitInterfacePragmas = emptyIdSet
333               | otherwise                = worker_ids   `unionIdSets`
334                                            unfold_ids   `unionIdSets`
335                                            spec_ids
336
337     worker_ids | has_worker = unitIdSet work_id
338                | otherwise  = emptyIdSet
339
340     spec_ids = foldr add emptyIdSet spec_list
341              where
342                add (_, _, rhs) = unionIdSets (find_fvs rhs)
343
344     unfold_ids | show_unfold = find_fvs rhs
345                | otherwise   = emptyIdSet
346
347     find_fvs expr = free_vars
348                   where
349                     (_,free_vars) = addExprFVs interesting emptyIdSet expr
350                     interesting bound id = isLocallyDefined id &&
351                                            not (id `elementOfIdSet` bound) &&
352                                            not (omitIfaceSigForId id)
353 \end{code}
354
355 \begin{code}
356 ifaceBinds :: Handle
357            -> IdSet             -- These Ids are needed already
358            -> [Id]              -- Ids used at code-gen time; they have better pragma info!
359            -> [CoreBinding]     -- In dependency order, later depend on earlier
360            -> IO ()
361
362 ifaceBinds hdl needed_ids final_ids binds
363   = mapIO (printForIface hdl) pretties >>
364     hPutStr hdl "\n"
365   where
366     final_id_map  = listToUFM [(id,id) | id <- final_ids]
367     get_idinfo id = case lookupUFM final_id_map id of
368                         Just id' -> idInfo id'
369                         Nothing  -> pprTrace "ifaceBinds not found:" (ppr id) $
370                                     idInfo id
371
372     pretties = go needed_ids (reverse binds)    -- Reverse so that later things will 
373                                                 -- provoke earlier ones to be emitted
374     go needed [] = if not (isEmptyIdSet needed) then
375                         pprTrace "ifaceBinds: free vars:" 
376                                   (sep (map ppr (idSetToList needed))) $
377                         []
378                    else
379                         []
380
381     go needed (NonRec id rhs : binds)
382         = case ifaceId get_idinfo needed False id rhs of
383                 Nothing                -> go needed binds
384                 Just (pretty, needed') -> pretty : go needed' binds
385
386         -- Recursive groups are a bit more of a pain.  We may only need one to
387         -- start with, but it may call out the next one, and so on.  So we
388         -- have to look for a fixed point.
389     go needed (Rec pairs : binds)
390         = pretties ++ go needed'' binds
391         where
392           (needed', pretties) = go_rec needed pairs
393           needed'' = needed' `minusIdSet` mkIdSet (map fst pairs)
394                 -- Later ones may spuriously cause earlier ones to be "needed" again
395
396     go_rec :: IdSet -> [(Id,CoreExpr)] -> (IdSet, [SDoc])
397     go_rec needed pairs
398         | null pretties = (needed, [])
399         | otherwise     = (final_needed, more_pretties ++ pretties)
400         where
401           reduced_pairs                 = [pair | (pair,Nothing) <- pairs `zip` maybes]
402           pretties                      = catMaybes maybes
403           (needed', maybes)             = mapAccumL do_one needed pairs
404           (final_needed, more_pretties) = go_rec needed' reduced_pairs
405
406           do_one needed (id,rhs) = case ifaceId get_idinfo needed True id rhs of
407                                         Nothing                -> (needed,  Nothing)
408                                         Just (pretty, needed') -> (needed', Just pretty)
409 \end{code}
410
411
412 %************************************************************************
413 %*                                                                      *
414 \subsection{Random small things}
415 %*                                                                      *
416 %************************************************************************
417
418 \begin{code}
419 ifaceTyCons hdl tycons   = hPutCol hdl upp_tycon (sortLt (<) (filter (for_iface_name . getName) tycons ))
420 ifaceClasses hdl classes = hPutCol hdl upp_class (sortLt (<) (filter (for_iface_name . getName) classes))
421
422 for_iface_name name = isLocallyDefined name && 
423                       not (isWiredInName name)
424
425 upp_tycon tycon = ifaceTyCon tycon
426 upp_class clas  = ifaceClass clas
427 \end{code}
428
429
430 \begin{code}
431 ifaceTyCon :: TyCon -> SDoc
432 ifaceTyCon tycon
433   | isSynTyCon tycon
434   = hsep [ ptext SLIT("type"),
435            ppr (getName tycon),
436            pprTyVarBndrs tyvars,
437            ptext SLIT("="),
438            ppr ty,
439            semi
440     ]
441   where
442     (tyvars, ty) = getSynTyConDefn tycon
443
444 ifaceTyCon tycon
445   | isAlgTyCon tycon
446   = hsep [ ptext keyword,
447            ppr_decl_context (tyConTheta tycon),
448            ppr (getName tycon),
449            pprTyVarBndrs (tyConTyVars tycon),
450            ptext SLIT("="),
451            hsep (punctuate (ptext SLIT(" | ")) (map ppr_con (tyConDataCons tycon))),
452            semi
453     ]
454   where
455     keyword | isNewTyCon tycon = SLIT("newtype")
456             | otherwise        = SLIT("data")
457
458     ppr_con data_con 
459         | null field_labels
460         = hsep [ ppr name,
461                   hsep (map ppr_arg_ty (strict_marks `zip` arg_tys))
462                 ]
463
464         | otherwise
465         = hsep [ ppr name,
466                   braces $ hsep $ punctuate comma (map ppr_field (strict_marks `zip` field_labels))
467                 ]
468           where
469            field_labels   = dataConFieldLabels data_con
470            arg_tys        = dataConRawArgTys   data_con
471            strict_marks   = dataConStrictMarks data_con
472            name           = getName            data_con
473
474     ppr_arg_ty (strict_mark, ty) = ppr_strict_mark strict_mark <> pprParendType ty
475
476     ppr_strict_mark NotMarkedStrict = empty
477     ppr_strict_mark MarkedStrict    = ptext SLIT("! ")
478                                 -- The extra space helps the lexical analyser that lexes
479                                 -- interface files; it doesn't make the rigid operator/identifier
480                                 -- distinction, so "!a" is a valid identifier so far as it is concerned
481
482     ppr_field (strict_mark, field_label)
483         = hsep [ ppr (fieldLabelName field_label),
484                   ptext SLIT("::"),
485                   ppr_strict_mark strict_mark <> pprParendType (fieldLabelType field_label)
486                 ]
487
488 ifaceTyCon tycon
489   = pprPanic "pprIfaceTyDecl" (ppr tycon)
490
491 ifaceClass clas
492   = hsep [ptext SLIT("class"),
493            ppr_decl_context sc_theta,
494            ppr clas,                    -- Print the name
495            pprTyVarBndrs clas_tyvars,
496            pp_ops,
497            semi
498           ]
499    where
500      (clas_tyvars, sc_theta, _, sel_ids, defms) = classBigSig clas
501
502      pp_ops | null sel_ids  = empty
503             | otherwise = hsep [ptext SLIT("where"),
504                                  braces (hsep (punctuate semi (zipWith ppr_classop sel_ids defms)))
505                           ]
506
507      ppr_classop sel_id maybe_defm
508         = ASSERT( sel_tyvars == clas_tyvars)
509           hsep [ppr (getOccName sel_id),
510                 if maybeToBool maybe_defm then equals else empty,
511                 ptext SLIT("::"),
512                 ppr op_ty
513           ]
514         where
515           (sel_tyvars, _, op_ty) = splitSigmaTy (idType sel_id)
516
517 ppr_decl_context :: ThetaType -> SDoc
518 ppr_decl_context [] = empty
519 ppr_decl_context theta
520   = braces (hsep (punctuate comma (map (ppr_dict) theta)))
521     <> 
522     ptext SLIT(" =>")
523   where
524     ppr_dict (clas,tys) = ppr clas <+> hsep (map pprParendType tys)
525 \end{code}
526
527 %************************************************************************
528 %*                                                                      *
529 \subsection{Random small things}
530 %*                                                                      *
531 %************************************************************************
532
533 When printing export lists, we print like this:
534         Avail   f               f
535         AvailTC C [C, x, y]     C(x,y)
536         AvailTC C [x, y]        C!(x,y)         -- Exporting x, y but not C
537
538 \begin{code}
539 upp_avail NotAvailable      = empty
540 upp_avail (Avail name)      = upp_occname (getOccName name)
541 upp_avail (AvailTC name []) = empty
542 upp_avail (AvailTC name ns) = hcat [upp_occname (getOccName name), bang, upp_export ns']
543                             where
544                               bang | name `elem` ns = empty
545                                    | otherwise      = char '|'
546                               ns' = filter (/= name) ns
547
548 upp_export []    = empty
549 upp_export names = parens (hsep (map (upp_occname . getOccName) names)) 
550
551 upp_fixity (occ, fixity) = hcat [ppr fixity, space, upp_occname occ, semi]
552
553 ppr_unqual_name :: NamedThing a => a -> SDoc            -- Just its occurrence name
554 ppr_unqual_name name = upp_occname (getOccName name)
555
556 upp_occname :: OccName -> SDoc
557 upp_occname occ = ptext (occNameString occ)
558 \end{code}
559
560
561 %************************************************************************
562 %*                                                                      *
563 \subsection{Comparisons
564 %*                                                                      *
565 %************************************************************************
566                                  
567
568 The various sorts above simply prevent unnecessary "wobbling" when
569 things change that don't have to.  We therefore compare lexically, not
570 by unique
571
572 \begin{code}
573 lt_avail :: AvailInfo -> AvailInfo -> Bool
574
575 a1 `lt_avail` a2 = availName a1 `lt_name` availName a2
576
577 lt_name :: Name -> Name -> Bool
578 n1 `lt_name` n2 = modAndOcc n1 < modAndOcc n2
579
580 lt_lexical :: NamedThing a => a -> a -> Bool
581 lt_lexical a1 a2 = getName a1 `lt_name` getName a2
582
583 lt_imp_vers :: ImportVersion a -> ImportVersion a -> Bool
584 lt_imp_vers (m1,_,_,_) (m2,_,_,_) = m1 < m2
585
586 sort_versions vs = sortLt lt_vers vs
587
588 lt_vers :: LocalVersion Name -> LocalVersion Name -> Bool
589 lt_vers (n1,v1) (n2,v2) = n1 `lt_name` n2
590 \end{code}
591
592
593 \begin{code}
594 hPutCol :: Handle 
595         -> (a -> SDoc)
596         -> [a]
597         -> IO ()
598 hPutCol hdl fmt xs = mapIO (printForIface hdl . fmt) xs
599
600 mapIO :: (a -> IO b) -> [a] -> IO ()
601 mapIO f []     = return ()
602 mapIO f (x:xs) = f x >> mapIO f xs
603 \end{code}