Chaddai:
Thanks for your excellent explanation of why using a temp file is necessary and a good thing to do.

The problem also with using withFile and a lambda is that in my infinite Haskell beginnerness, I do not know how to get the
contents out of the lambda for use later for the second try of withFile in WriteMode.

As in LYAH
  1.     withFile "girlfriend.txt" ReadMode (\handle -> do  
  2.         contents <- hGetContents handle     
  3.         putStr contents)

how to retrieve contents for later use? Scope of contents variable in inside lambda only it would appear.

Can I declare an empty contents IO String before the withFile lambda somehow?


Thanks



On Thu, Feb 5, 2015 at 4:33 PM, Chaddaï Fouché <chaddai.fouche@gmail.com> wrote:
On Thu, Feb 5, 2015 at 10:30 PM, Geoffrey Bays <charioteer7@gmail.com> wrote:
Francesco:

Unfortunately, using withFile I get the same error as before with handles: hPutStr: illegal operation (handle is closed).


This error suggests you're forgetting to reopen your file in WriteMode once withFile closed it (you did read the documentation of withFile ?). Trying to write on a closed handle is an exercise in futility.

--
Jedaï


_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners