Opens a file, manipulates it with the provided function and closes the
handle before returning. The
Handle can be written to using the
hPutStr and
hPutStrLn functions.
withFile is essentially the
bracket pattern, specialized
to files. This should be preferred over
openFile +
hClose as it properly deals with (asynchronous) exceptions. In
cases where
withFile is insufficient, for instance because the
it is not statically known when manipulating the
Handle has
finished, one should consider other safe paradigms for resource usage,
such as the
ResourceT transformer from the
resourcet
package, before resorting to
openFile and
hClose.