[Haskell-beginners] File I/O: reading from, writing to, same file in one function

Geoffrey Bays charioteer7 at gmail.com
Thu Feb 5 21:30:40 UTC 2015


Francesco:

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

Any other suggestions for reading and writing to the same file in the same
function?

Thanks

On Thu, Feb 5, 2015 at 3:26 PM, Francesco Ariis <fa-ml at ariis.it> wrote:

> On Thu, Feb 05, 2015 at 02:51:52PM -0500, Geoffrey Bays wrote:
> > As I work my way through Learn You as Haskell, I have been writing small
> > File IO programs.
> > Unlike the example in that book, where the author reads from one file,
> > writes altered data to a temp file and then deletes the original file and
> > renames the temp file, I have been trying to read from a given file,
> alter
> > the data and then overwrite the same file with the new data. Is this
> > possible?
>
> Try `withFile` [1], there is an example of its usage in chapter 9 of
> LYAH [2].
>
> [1]
> https://downloads.haskell.org/~ghc/6.12.2/docs/html/libraries/base-4.2.0.1/System-IO.html#v%3AwithFile
> [2] http://learnyouahaskell.com/input-and-output#files-and-streams
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150205/108b6e2c/attachment-0001.html>


More information about the Beginners mailing list