sdp-io-0.2: SDP IO extension
Copyright(c) Andrey Mulik 2020
LicenseBSD-style
Maintainerwork.a.mulik@gmail.com
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

System.IO.Classes

Description

System.IO.Classes provides generalized path and file classes.

Synopsis

Export

Generalized path

class IsFilePath path where Source #

IsFilePath is type class of file path (data destination) representations.

Minimal complete definition

hOpenWith, hOpenTemp

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:

  • isAlreadyInUseError if the file is already open and cannot be reopened
  • isDoesNotExistError if the file does not exist
  • isPermissionError if 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:

hOpenTemp :: MonadIO io => path -> io (path, Handle) Source #

Open new temp file Handle by given source identifier.

Instances

Instances details
IsFilePath FilePath Source # 
Instance details

Defined in System.IO.Classes

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:

If hPutContents changes the recording mode (buffering, binary/text), it should return the original Handle settings.

Instances

Instances details
IsFile String Source # 
Instance details

Defined in System.IO.Classes

Methods

hGetContents :: MonadIO io => Handle -> io String Source #

hPutContents :: MonadIO io => Handle -> String -> io () Source #

getContents :: (MonadIO io, IsFile file) => io file Source #

putContents :: (MonadIO io, IsFile file) => file -> io () Source #

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.

Minimal complete definition

hGetLine, hPutStr

Methods

hGetLine :: MonadIO io => Handle -> io text Source #

Read one text line from handle.

hPutStr :: MonadIO io => Handle -> text -> io () Source #

Put text to handle.

hPutStrLn :: MonadIO io => Handle -> text -> io () Source #

Put text line to handle.

Instances

Instances details
IsTextFile String Source # 
Instance details

Defined in System.IO.Classes

Methods

hGetLine :: MonadIO io => Handle -> io String Source #

hPutStr :: MonadIO io => Handle -> String -> io () Source #

hPutStrLn :: MonadIO io => Handle -> String -> io () Source #

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.

gets :: (MonadIO io, IsTextFile text) => io text Source #

Short version of getLine.

puts :: (MonadIO io, IsTextFile text) => text -> io () Source #

Short version of putStrLn.