Ralf Krueger wrote:
> I think, the problem can be solved by using the IO library and some
> strictness:
> 
>  import IO
> 
>  main = do text <- readFile "xxx"
>            text' <- process $! text
>            file <- openFile "xxx" WriteMode
>            hPutStr file text'
>            hClose file
> 
> seems to work. The file will be read completly befor it is
> re-opened for writing.

Without trying it for myself, I have some doubts about the above code.
IIRC ($!) evaluates its second argument only to WHNF, i.e. only until
the toplevel constructor ((:) or [] in the case of lists) is known.
Perhaps you had luck because the files were short enough to fit into
the buffer of the underlying IO system. A more promising way is
probably:

   main = readFile "xxx" >>= hyper >>= process >>= writeFile "xxx"

   -- hack for hyperstrictness
   hyper txt | length txt >= 0 = return txt
             | otherwise       = error "never happens"

And using hGetBuf{,BA}Full from GHC's upcoming IOExts module would be
a completely different way.

-- 
Sven Panne                                        Tel.: +49/89/2178-2235
LMU, Institut fuer Informatik                     FAX : +49/89/2178-2211
LFE Programmier- und Modellierungssprachen              Oettingenstr. 67
mailto:[EMAIL PROTECTED]            D-80538 Muenchen
http://www.informatik.uni-muenchen.de/~Sven.Panne

Reply via email to