[Haskell-beginners] File I/O: reading from, writing to, same file in one function
Chaddaï Fouché
chaddai.fouche at gmail.com
Thu Feb 5 21:42:38 UTC 2015
If you're still wedded to your notion (I strongly urge you to use the
proper way with temp file and renaming, even making it a function if you
need to repeat this several times) :
readModifyWrite fileName modify = do
contents <- readFile fileName
evaluate (length contents) -- ensure that contents is evaluated and the
handle closed
writeFile fileName (modify contents)
This should work (but may consume a fair bit of memory, you should probably
use Text or ByteString anyway and use the proper way instead).
--
Jedaï
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150205/2df91962/attachment.html>
More information about the Beginners
mailing list