| Copyright | (c) Andrey Mulik 2020 |
|---|---|
| License | BSD-style |
| Maintainer | work.a.mulik@gmail.com |
| Portability | portable |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
System.IO.Classes
Description
System.IO.Classes provides generalized path and file classes.
Synopsis
- module System.IO.Handle
- module System.IO.Error
- class IsFilePath path where
- class IsFile file where
- hGetContents :: MonadIO io => Handle -> io file
- hPutContents :: MonadIO io => Handle -> file -> io ()
- getContents :: (MonadIO io, IsFile file) => io file
- putContents :: (MonadIO io, IsFile file) => file -> io ()
- withFile :: (MonadIO io, IsFilePath path) => path -> IOMode -> (Handle -> IO a) -> io a
- readFile :: (MonadIO io, IsFilePath p, IsFile f) => p -> io f
- writeFile :: (MonadIO io, IsFilePath p, IsFile f) => p -> f -> io ()
- appendFile :: (MonadIO io, IsFilePath p, IsFile f) => p -> f -> io ()
- class IsFile text => IsTextFile text where
- getLine :: (MonadIO io, IsTextFile text) => io text
- putStr :: (MonadIO io, IsTextFile text) => text -> io ()
- putStrLn :: (MonadIO io, IsTextFile text) => text -> io ()
- gets :: (MonadIO io, IsTextFile text) => io text
- puts :: (MonadIO io, IsTextFile text) => text -> io ()
Export
module System.IO.Handle
module System.IO.Error
Generalized path
class IsFilePath path where Source #
IsFilePath is type class of file path (data destination) representations.
Methods
hOpen :: MonadIO io => IOMode -> path -> io Handle Source #
hOpen path mode open new text handle with block buffering and given
mode using path identifier.
This operation may fail with:
isAlreadyInUseErrorif the file is already open and cannot be reopenedisDoesNotExistErrorif the file does not existisPermissionErrorif the user doesn't have permission to open the file
hOpenWith :: MonadIO io => IOMode -> path -> BufferMode -> Bool -> io Handle Source #
hOpenWith path mode buf bin open new handle with buffering mode buf,
binary mode bin and IOMode mode using path identifier.
This operation may fail with:
isAlreadyInUseErrorif the file is already open and cannot be reopenedisDoesNotExistErrorif the file does not existisPermissionErrorif the user doesn't have permission to open the file
hOpenTemp :: MonadIO io => path -> io (path, Handle) Source #
Open new temp file Handle by given source identifier.
Generalized file
class IsFile file where Source #
IsFile is a type class that represents the contents of a file.
IsFile provides only basic read and write operations. It doesn't allow, for
example, changing the IOMode or handle the concatenation of the file
contents with the appendable information.
Methods
hGetContents :: MonadIO io => Handle -> io file Source #
hGetContents hdl reads the contents of the file. Reading may be both
lazily (in this case hdl should be semi-closed until the file end is
reached) or strictly. After reading the file, hdl should be closed.
Once a semi-closed handle becomes closed, the contents becomes fixed. The contents of this final value is only partially specified: it will contain at least all the items of the stream that were evaluated prior to the handle becoming closed.
This operation may fail with:
- isEOFError if the end of file has been reached.
hPutContents :: MonadIO io => Handle -> file -> io () Source #
hPutContents hdl file writes the file contents to hdl.
This operation may fail with:
isFullErrorif the device is full; orisPermissionErrorif another system resource limit would be exceeded.
If hPutContents changes the recording mode (buffering, binary/text),
it should return the original Handle settings.
getContents :: (MonadIO io, IsFile file) => io file Source #
Just hGetContents stdin.
putContents :: (MonadIO io, IsFile file) => file -> io () Source #
Just hPutContents stdout.
withFile :: (MonadIO io, IsFilePath path) => path -> IOMode -> (Handle -> IO a) -> io a Source #
withFile path mode act opens a file using hOpen and passes the resulting
handle to the computation act. The handle will be closed on exit from
withFile, whether by normal termination or by raising an exception.
If closing the handle raises an exception, then this exception will be raised by withFile rather than any exception raised by act.
readFile :: (MonadIO io, IsFilePath p, IsFile f) => p -> io f Source #
The readFile function reads a file and returns its contents.
The specifics of reading a file (laziness/strictness, possible exceptions)
depend on the type of resource and the hGetContents implementation.
writeFile :: (MonadIO io, IsFilePath p, IsFile f) => p -> f -> io () Source #
writeFile path file function writes the file value, to the path.
appendFile :: (MonadIO io, IsFilePath p, IsFile f) => p -> f -> io () Source #
appendFile path file appends the file value, to the path.
Text IO
class IsFile text => IsTextFile text where Source #
IsTextFile is a type class of text file representations.
getLine :: (MonadIO io, IsTextFile text) => io text Source #
Same as hGetLine stdin.
putStr :: (MonadIO io, IsTextFile text) => text -> io () Source #
Same as hPutStr stdout.
putStrLn :: (MonadIO io, IsTextFile text) => text -> io () Source #
Same as hPutStrLn stdout.