
Hello All, I wrote a small haskell program that amongst other things parses some files to manipulate them. During runtime I want the program to output information about the status every time another file is parsed. That doesn't work, the output appears much later, mostly not until end of program. But I need these outputs at that specific time, so what can I do to manage it? Thanks Nicole

Nicole Gabler
During runtime I want the program to output = information about the status every time another file is parsed. That = doesn't work, the output appears much later, mostly not until end of = program. But I need these outputs at that specific time, so what can I = do to manage it?
Perhaps the following fragment from my prelude extensions helps. It requires ``import IO''. Most probably you would either be calling
printList "\n" statusInformationList
or factor out the flushing part for interleaving with your other IO actions. Wolfram %{{{ hPutList, printList It is frequently annoying if a long-running program writes a list of items to a channel or file, and while it calculates the next item, the last item has usually not yet been (completely) written because at least part of it is still held in some output buffer. The following functions flush the output buffer after every item. The most general variant, \verb|hPutList|, is parameterised by a separator string for list items, a \verb|shows| function for items, and a handle for output. The variant \verb|putList| writes always to the standard output channel, and \verb|printList| in addition uses the \verb|shows| function supplied by the type class system. \begin{code} hPutList :: String -> (a -> ShowS) -> Handle -> [a] -> IO () hPutList sep shows h = mapM_ f where f x = hPutStr h (shows x sep) >> hFlush h putList :: String -> (a -> ShowS) -> [a] -> IO () putList sep shows = hPutList sep shows stdout printList :: Show a => String -> [a] -> IO () printList sep = putList sep shows \end{code} %}}}
participants (3)
-
kahl@heraklit.informatik.unibw-muenchen.de
-
Nicole Gabler
-
Nicole Gabler