| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Universum.Lifted.File
Description
Lifted versions of functions working with files and common IO.
All functions are specialized to Text.
Synopsis
- appendFile :: MonadIO m => FilePath -> Text -> m ()
- getLine :: MonadIO m => m Text
- readFile :: MonadIO m => FilePath -> m Text
- writeFile :: MonadIO m => FilePath -> Text -> m ()
- withFile :: (MonadIO m, MonadMask m) => FilePath -> IOMode -> (Handle -> m a) -> m a
- openFile :: MonadIO m => FilePath -> IOMode -> m Handle
- hClose :: MonadIO m => Handle -> m ()
Documentation
appendFile :: MonadIO m => FilePath -> Text -> m () Source #
Lifted version of appendFile.
withFile :: (MonadIO m, MonadMask m) => FilePath -> IOMode -> (Handle -> m a) -> m a Source #
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.