Copyright | © 2016 All rights reserved. |
---|---|
License | GPL-3 |
Maintainer | Evan Cofsky <evan@theunixman.com> |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
- putStr :: (MonadIO m, Printable p) => p -> m ()
- putStrLn :: (MonadIO m, Printable p) => p -> m ()
- managed :: (forall r. (a -> IO r) -> IO r) -> Managed a
- data Managed a :: * -> *
- class MonadIO m => MonadManaged m where
- runManaged :: Managed () -> IO ()
- data TempFile
- tfPath :: Lens' TempFile AbsFile
- tfHandle :: Lens' TempFile Handle
- tempFile :: AbsDir -> RelFile -> Managed TempFile
- class Monad m => MonadIO m where
- liftIO :: MonadIO m => forall a. IO a -> m a
- hSeek :: Handle -> SeekMode -> Integer -> IO ()
- data SeekMode :: *
- data IOMode :: *
- file :: AbsRel ar => File ar -> IOMode -> Managed Handle
- tfile :: AbsRel ar => File ar -> IOMode -> Managed Handle
- textMode :: MonadIO m => Handle -> m ()
- binaryMode :: MonadIO m => Handle -> m ()
- hIsEOF :: MonadIO m => Handle -> m Bool
- hClose :: MonadIO m => Handle -> m ()
- doesFileExist :: (MonadIO m, AbsRel ar) => File ar -> m Bool
- removeFile :: (MonadIO m, AbsRel ar) => File ar -> m ()
- data Handle :: *
- stdin :: Handle
- stdout :: Handle
- stderr :: Handle
Documentation
A managed resource that you acquire using with
class MonadIO m => MonadManaged m where #
You can embed a Managed
action within any Monad
that implements
MonadManaged
by using the using
function
All instances must obey the following two laws:
using (return x) = return x using (m >>= f) = using m >>= \x -> using (f x)
MonadManaged Managed | |
MonadManaged m => MonadManaged (MaybeT m) | |
MonadManaged m => MonadManaged (IdentityT * m) | |
(Monoid w, MonadManaged m) => MonadManaged (WriterT w m) | |
(Monoid w, MonadManaged m) => MonadManaged (WriterT w m) | |
MonadManaged m => MonadManaged (StateT s m) | |
MonadManaged m => MonadManaged (StateT s m) | |
MonadManaged m => MonadManaged (ExceptT e m) | |
MonadManaged m => MonadManaged (ReaderT * r m) | |
MonadManaged m => MonadManaged (ContT * r m) | |
(Monoid w, MonadManaged m) => MonadManaged (RWST r w s m) | |
(Monoid w, MonadManaged m) => MonadManaged (RWST r w s m) | |
runManaged :: Managed () -> IO () #
Run a Managed
computation, enforcing that no acquired resources leak
class Monad m => MonadIO m where #
Monads in which IO
computations may be embedded.
Any monad built by applying a sequence of monad transformers to the
IO
monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO
is a transformer of monads:
MonadIO IO | |
MonadIO Managed | |
MonadIO m => MonadIO (MaybeT m) | |
MonadIO m => MonadIO (ListT m) | |
MonadIO m => MonadIO (ResourceT m) | |
MonadIO m => MonadIO (IdentityT * m) | |
(Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
(Monoid w, MonadIO m) => MonadIO (WriterT w m) | |
MonadIO m => MonadIO (StateT s m) | |
MonadIO m => MonadIO (StateT s m) | |
(Error e, MonadIO m) => MonadIO (ErrorT e m) | |
(Functor f, MonadIO m) => MonadIO (FreeT f m) | |
MonadIO m => MonadIO (ExceptT e m) | |
MonadIO m => MonadIO (PlanT k o m) | |
MonadIO m => MonadIO (ReaderT * r m) | |
MonadIO m => MonadIO (ContT * r m) | |
(Monoid w, MonadIO m) => MonadIO (RWST r w s m) | |
(Monoid w, MonadIO m) => MonadIO (RWST r w s m) | |
hSeek :: Handle -> SeekMode -> Integer -> IO () #
Computation hSeek
hdl mode i
sets the position of handle
hdl
depending on mode
.
The offset i
is given in terms of 8-bit bytes.
If hdl
is block- or line-buffered, then seeking to a position which is not
in the current buffer will first cause any items in the output buffer to be
written to the device, and then cause the input buffer to be discarded.
Some handles may not be seekable (see hIsSeekable
), or only support a
subset of the possible positioning operations (for instance, it may only
be possible to seek to the end of a tape, or to a positive offset from
the beginning or current position).
It is not possible to set a negative I/O position, or for
a physical file, an I/O position beyond the current end-of-file.
This operation may fail with:
isIllegalOperationError
if the Handle is not seekable, or does not support the requested seek mode.isPermissionError
if a system resource limit would be exceeded.
A mode that determines the effect of hSeek
hdl mode i
.
AbsoluteSeek | the position of |
RelativeSeek | the position of |
SeekFromEnd | the position of |
See openFile
binaryMode :: MonadIO m => Handle -> m () Source #
Haskell defines operations to read and write characters from and to files,
represented by values of type Handle
. Each value of this type is a
handle: a record used by the Haskell run-time system to manage I/O
with file system objects. A handle has at least the following properties:
- whether it manages input or output or both;
- whether it is open, closed or semi-closed;
- whether the object is seekable;
- whether buffering is disabled, or enabled on a line or block basis;
- a buffer (whose length may be zero).
Most handles will also have a current I/O position indicating where the next
input or output operation will occur. A handle is readable if it
manages only input or both input and output; likewise, it is writable if
it manages only output or both input and output. A handle is open when
first allocated.
Once it is closed it can no longer be used for either input or output,
though an implementation cannot re-use its storage while references
remain to it. Handles are in the Show
and Eq
classes. The string
produced by showing a handle is system dependent; it should include
enough information to identify the handle for debugging. A handle is
equal according to ==
only to itself; no attempt
is made to compare the internal state of different handles for equality.