| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Effectful.FileSystem.HandleWriter.Dynamic
Description
Provides a dynamic effect for writing to a handle.
Since: 0.1
Synopsis
- data HandleWriter (a :: Type -> Type) b where
- OpenBinaryFile :: forall (a :: Type -> Type). OsPath -> Bool -> HandleWriter a (Handle 'HandleModeWrite)
- WithBinaryFile :: forall (a :: Type -> Type) b. OsPath -> Bool -> (Handle 'HandleModeWrite -> a b) -> HandleWriter a b
- HClose :: forall (p :: HandleMode) (a :: Type -> Type). CanWrite p => Handle p -> HandleWriter a ()
- HFlush :: forall (p :: HandleMode) (a :: Type -> Type). CanWrite p => Handle p -> HandleWriter a ()
- HSetFileSize :: forall (p :: HandleMode) (a :: Type -> Type). CanWrite p => Handle p -> Integer -> HandleWriter a ()
- HSetBuffering :: forall (p :: HandleMode) (a :: Type -> Type). CanWrite p => Handle p -> BufferMode -> HandleWriter a ()
- HSeek :: forall (p :: HandleMode) (a :: Type -> Type). CanWrite p => Handle p -> SeekMode -> Integer -> HandleWriter a ()
- HTell :: forall (p :: HandleMode) (a :: Type -> Type). CanWrite p => Handle p -> HandleWriter a Integer
- HSetEcho :: forall (p :: HandleMode) (a :: Type -> Type). CanWrite p => Handle p -> Bool -> HandleWriter a ()
- HPut :: forall (p :: HandleMode) (a :: Type -> Type). CanWrite p => Handle p -> ByteString -> HandleWriter a ()
- HPutNonBlocking :: forall (p :: HandleMode) (a :: Type -> Type). CanWrite p => Handle p -> ByteString -> HandleWriter a ByteString
- HLockRaw :: forall (p :: HandleMode) (a :: Type -> Type). CanWrite p => Handle p -> HandleWriter a ()
- HTryLockRaw :: forall (p :: HandleMode) (a :: Type -> Type). CanWrite p => Handle p -> HandleWriter a Bool
- HUnlockRaw :: forall (p :: HandleMode) (a :: Type -> Type). CanWrite p => Handle p -> HandleWriter a ()
- openBinaryFile :: forall (es :: [Effect]). (HandleWriter :> es, HasCallStack) => OsPath -> Bool -> Eff es (Handle 'HandleModeWrite)
- withBinaryFile :: forall (es :: [Effect]) a. (HandleWriter :> es, HasCallStack) => OsPath -> Bool -> (Handle 'HandleModeWrite -> Eff es a) -> Eff es a
- hClose :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Eff es ()
- hFlush :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Eff es ()
- hSetFileSize :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Integer -> Eff es ()
- hSetBuffering :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> BufferMode -> Eff es ()
- hSeek :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> SeekMode -> Integer -> Eff es ()
- hTell :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Eff es Integer
- hSetEcho :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Bool -> Eff es ()
- hPut :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> ByteString -> Eff es ()
- hPutNonBlocking :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> ByteString -> Eff es ByteString
- hLockRaw :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Eff es ()
- hTryLockRaw :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Eff es Bool
- hUnlockRaw :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Eff es ()
- runHandleWriter :: forall (es :: [Effect]) a. (HasCallStack, IOE :> es) => Eff (HandleWriter ': es) a -> Eff es a
- data Handle (p :: HandleMode)
- data HandleMode = HandleModeWrite
- type family CanWrite (hm :: HandleMode) where ...
- data LockedHandle (p :: HandleMode)
- liftLocked :: forall (p :: HandleMode) a. HasCallStack => (HasCallStack => Handle p -> a) -> LockedHandle p -> a
- withLockedFile :: forall (p :: HandleMode) (es :: [Effect]) a. (CanWrite p, HasCallStack, HandleWriter :> es) => Handle p -> (LockedHandle p -> Eff es a) -> Eff es a
- withTryLockedFile :: forall (p :: HandleMode) a (es :: [Effect]). (CanWrite p, HasCallStack, HandleWriter :> es) => Handle p -> (LockedHandle p -> Eff es a) -> Eff es (Maybe a)
- hLock :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HasCallStack, HandleWriter :> es) => Handle p -> Eff es (LockedHandle p)
- hTryLock :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HasCallStack, HandleWriter :> es) => Handle p -> Eff es (Maybe (LockedHandle p))
- hUnlock :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HasCallStack, HandleWriter :> es) => LockedHandle p -> Eff es (Handle p)
- withLockedFileRaw :: forall (p :: HandleMode) (es :: [Effect]) a. (CanWrite p, HasCallStack, HandleWriter :> es) => Handle p -> Eff es a -> Eff es a
- withTryLockedFileRaw :: forall (p :: HandleMode) a (es :: [Effect]). (CanWrite p, HasCallStack, HandleWriter :> es) => Handle p -> Eff es a -> Eff es (Maybe a)
- hPutUtf8 :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Text -> Eff es ()
- hPutNonBlockingUtf8 :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Text -> Eff es ByteString
- die :: forall (es :: [Effect]) a. (HandleWriter :> es, HasCallStack) => String -> Eff es a
- data BufferMode
- data ByteString
- data IOMode
- type OsPath = OsString
- data SeekMode
- data Text
Effect
data HandleWriter (a :: Type -> Type) b where Source #
Dynamic effect for writing to a handle.
Since: 0.1
Constructors
Instances
| ShowEffect HandleWriter Source # | Since: 0.1 |
Defined in Effectful.FileSystem.HandleWriter.Dynamic Methods showEffectCons :: forall (m :: Type -> Type) a. HandleWriter m a -> String Source # | |
| type DispatchOf HandleWriter Source # | Since: 0.1 |
Defined in Effectful.FileSystem.HandleWriter.Dynamic | |
openBinaryFile :: forall (es :: [Effect]). (HandleWriter :> es, HasCallStack) => OsPath -> Bool -> Eff es (Handle 'HandleModeWrite) Source #
Lifted openBinaryFile.
Since: 0.1
withBinaryFile :: forall (es :: [Effect]) a. (HandleWriter :> es, HasCallStack) => OsPath -> Bool -> (Handle 'HandleModeWrite -> Eff es a) -> Eff es a Source #
Lifted withBinaryFile.
Since: 0.1
hClose :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Eff es () Source #
Lifted hClose.
Since: 0.1
hFlush :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Eff es () Source #
Lifted hFlush.
Since: 0.1
hSetFileSize :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Integer -> Eff es () Source #
Lifted hSetFileSize.
Since: 0.1
hSetBuffering :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> BufferMode -> Eff es () Source #
Lifted hSetBuffering.
Since: 0.1
hSeek :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> SeekMode -> Integer -> Eff es () Source #
Lifted hSeek.
Since: 0.1
hTell :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Eff es Integer Source #
Lifted hTell.
Since: 0.1
hSetEcho :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Bool -> Eff es () Source #
Lifted hSetEcho.
Since: 0.1
hPut :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> ByteString -> Eff es () Source #
Lifted hPut.
Since: 0.1
hPutNonBlocking :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> ByteString -> Eff es ByteString Source #
Lifted hPutNonBlocking.
Since: 0.1
hLockRaw :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Eff es () Source #
Attempts to exclusively lock a file, blocking or throwing an exception upon failure.
Since: 0.1
hTryLockRaw :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Eff es Bool Source #
Attempts to exclusively lock a file.
Since: 0.1
hUnlockRaw :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Eff es () Source #
Unlocks a locked file.
Since: 0.1
Handlers
runHandleWriter :: forall (es :: [Effect]) a. (HasCallStack, IOE :> es) => Eff (HandleWriter ': es) a -> Eff es a Source #
Runs HandleWriter in IO.
Since: 0.1
File handles
data Handle (p :: HandleMode) Source #
Wrapper for file handles that includes an index for the mode.
Since: 0.1
Instances
| HasField "unHandle" (Handle p :: Type) Handle Source # | Since: 0.1 |
Defined in Effectful.FileSystem.Handle.Internal | |
| HasField "unLockedHandle" (LockedHandle p :: Type) (Handle p :: Type) Source # | Since: 0.1 |
Defined in Effectful.FileSystem.Handle.Internal Methods getField :: LockedHandle p -> Handle p # | |
| (k ~ A_Getter, a ~ Handle, b ~ Handle) => LabelOptic "unHandle" k (Handle p) (Handle p) a b Source # | Since: 0.1 |
Defined in Effectful.FileSystem.Handle.Internal | |
type family CanWrite (hm :: HandleMode) where ... Source #
Since: 0.1
Equations
| CanWrite 'HandleModeRead = Unsatisfiable ('Text "HandleModeRead does not have Write permission.") | |
| CanWrite 'HandleModeWrite = () | |
| CanWrite 'HandleModeReadWrite = () |
Locking
These functions bring some type-safety to file locking. Consider:
main :: (HandleWriter :> es) => Eff es () main = withBinaryFile path False $ \h -> do hLockRaw handle bs <- writeBytes @HandleModeWrite h hUnlockRaw handle print bs writeBytes :: (CanWrite p, HandleWriter :> es) => Handle p -> Eff es ByteString writeBytes handle = hPut handle "some bytes"
In this example, we could remove all locking logic from main and
everything would still compile. On the other hand:
main :: (HandleWriter :> es) => Eff es () main = withBinaryFile path False $ \h -> withLockedFile h $ \lh -> do bs <- writeBytes @HandleModeWrite lh print bs writeBytes :: (CanWrite p, HandleWriter :> es) => LockedHandle p -> Eff es ByteString writeBytes lockedHandle = liftLocked (\h -> hPut h "some bytes") lockedHandle
Removing withLockedFile would cause a compilation error, since writeBytes
requires a LockedHandle. The idea is to write most of the program's
logic in terms of LockedHandle, using liftLocked to lift Handle
functions.
data LockedHandle (p :: HandleMode) Source #
File handle with lock.
Since: 0.1
Instances
| HasField "unLockedHandle" (LockedHandle p :: Type) (Handle p :: Type) Source # | Since: 0.1 |
Defined in Effectful.FileSystem.Handle.Internal Methods getField :: LockedHandle p -> Handle p # | |
| (k ~ A_Getter, a ~ Handle p, b ~ Handle p) => LabelOptic "unLockedHandle" k (LockedHandle p) (LockedHandle p) a b Source # | Since: 0.1 |
Defined in Effectful.FileSystem.Handle.Internal Methods labelOptic :: Optic k NoIx (LockedHandle p) (LockedHandle p) a b Source # | |
liftLocked :: forall (p :: HandleMode) a. HasCallStack => (HasCallStack => Handle p -> a) -> LockedHandle p -> a Source #
Lifts a function on handle to one on locked handles.
Since: 0.1
Arguments
| :: forall (p :: HandleMode) (es :: [Effect]) a. (CanWrite p, HasCallStack, HandleWriter :> es) | |
| => Handle p | Handle to lock. |
| -> (LockedHandle p -> Eff es a) | Callback with locked handle. |
| -> Eff es a |
Runs a computation with an exclusively locked file.
Since: 0.1
Arguments
| :: forall (p :: HandleMode) a (es :: [Effect]). (CanWrite p, HasCallStack, HandleWriter :> es) | |
| => Handle p | Handle to lock. |
| -> (LockedHandle p -> Eff es a) | Handle callback. |
| -> Eff es (Maybe a) |
Like withSharedLockedFile, except the lock attempt does not block.
Since: 0.1
Arguments
| :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HasCallStack, HandleWriter :> es) | |
| => Handle p | Handle to lock. |
| -> Eff es (LockedHandle p) |
Like hLockRaw, but returns a LockedHandle.
Since: 0.1
Arguments
| :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HasCallStack, HandleWriter :> es) | |
| => Handle p | Handle to lock. |
| -> Eff es (Maybe (LockedHandle p)) |
Like hTryLockRaw, but returns a LockedHandle if it succeeds.
Since: 0.1
Arguments
| :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HasCallStack, HandleWriter :> es) | |
| => LockedHandle p | Handle to unlock. |
| -> Eff es (Handle p) |
Like hUnlockRaw, but returns the original handle.
Since: 0.1
Raw
Arguments
| :: forall (p :: HandleMode) (es :: [Effect]) a. (CanWrite p, HasCallStack, HandleWriter :> es) | |
| => Handle p | Handle to lock. |
| -> Eff es a | Callback with locked handle. |
| -> Eff es a |
withLockedFile without LockedHandle.
Since: 0.1
Arguments
| :: forall (p :: HandleMode) a (es :: [Effect]). (CanWrite p, HasCallStack, HandleWriter :> es) | |
| => Handle p | Handle to lock. |
| -> Eff es a | Handle callback. |
| -> Eff es (Maybe a) |
withTryLockedFileRaw without LockedHandle.
Since: 0.1
UTF-8 Utils
hPutUtf8 :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Text -> Eff es () Source #
hPut and encodeUtf8.
Since: 0.1
hPutNonBlockingUtf8 :: forall (p :: HandleMode) (es :: [Effect]). (CanWrite p, HandleWriter :> es, HasCallStack) => Handle p -> Text -> Eff es ByteString Source #
hPutNonBlocking and encodeUtf8.
Since: 0.1
Misc
die :: forall (es :: [Effect]) a. (HandleWriter :> es, HasCallStack) => String -> Eff es a Source #
Write given error message to stderr and terminate with exitFailure.
Since: 0.1
Re-exports
data BufferMode #
Three kinds of buffering are supported: line-buffering, block-buffering or no-buffering. These modes have the following effects. For output, items are written out, or flushed, from the internal buffer according to the buffer mode:
- line-buffering: the entire output buffer is flushed
whenever a newline is output, the buffer overflows,
a
hFlushis issued, or the handle is closed. - block-buffering: the entire buffer is written out whenever it
overflows, a
hFlushis issued, or the handle is closed. - no-buffering: output is written immediately, and never stored in the buffer.
An implementation is free to flush the buffer more frequently, but not less frequently, than specified above. The output buffer is emptied as soon as it has been written out.
Similarly, input occurs according to the buffer mode for the handle:
- line-buffering: when the buffer for the handle is not empty, the next item is obtained from the buffer; otherwise, when the buffer is empty, characters up to and including the next newline character are read into the buffer. No characters are available until the newline character is available or the buffer is full.
- block-buffering: when the buffer for the handle becomes empty, the next block of data is read into the buffer.
- no-buffering: the next input item is read and returned.
The
hLookAheadoperation implies that even a no-buffered handle may require a one-character buffer.
The default buffering mode when a handle is opened is implementation-dependent and may depend on the file system object which is attached to that handle. For most implementations, physical files will normally be block-buffered and terminals will normally be line-buffered.
Constructors
| NoBuffering | buffering is disabled if possible. |
| LineBuffering | line-buffering should be enabled if possible. |
| BlockBuffering (Maybe Int) | block-buffering should be enabled if possible.
The size of the buffer is |
Instances
| Read BufferMode # | Since: base-4.2.0.0 |
Defined in GHC.Internal.IO.Handle.Types Methods readsPrec :: Int -> ReadS BufferMode # readList :: ReadS [BufferMode] # readPrec :: ReadPrec BufferMode # readListPrec :: ReadPrec [BufferMode] # | |
| Show BufferMode # | Since: base-4.2.0.0 |
Defined in GHC.Internal.IO.Handle.Types Methods showsPrec :: Int -> BufferMode -> ShowS # show :: BufferMode -> String # showList :: [BufferMode] -> ShowS # | |
| Eq BufferMode # | Since: base-4.2.0.0 |
Defined in GHC.Internal.IO.Handle.Types | |
| Ord BufferMode # | Since: base-4.2.0.0 |
Defined in GHC.Internal.IO.Handle.Types Methods compare :: BufferMode -> BufferMode -> Ordering # (<) :: BufferMode -> BufferMode -> Bool # (<=) :: BufferMode -> BufferMode -> Bool # (>) :: BufferMode -> BufferMode -> Bool # (>=) :: BufferMode -> BufferMode -> Bool # max :: BufferMode -> BufferMode -> BufferMode # min :: BufferMode -> BufferMode -> BufferMode # | |
data ByteString #
A space-efficient representation of a Word8 vector, supporting many
efficient operations.
A ByteString contains 8-bit bytes, or by using the operations from
Data.ByteString.Char8 it can be interpreted as containing 8-bit
characters.
Instances
See openFile
Constructors
| ReadMode | |
| WriteMode | |
| AppendMode | |
| ReadWriteMode |
Type representing filenames/pathnames.
This type doesn't add any guarantees over OsString.
A mode that determines the effect of hSeek hdl mode i.
Constructors
| AbsoluteSeek | the position of |
| RelativeSeek | the position of |
| SeekFromEnd | the position of |
Instances
| Enum SeekMode # | Since: base-4.2.0.0 |
Defined in GHC.Internal.IO.Device | |
| Ix SeekMode # | Since: base-4.2.0.0 |
Defined in GHC.Internal.IO.Device Methods range :: (SeekMode, SeekMode) -> [SeekMode] # index :: (SeekMode, SeekMode) -> SeekMode -> Int # unsafeIndex :: (SeekMode, SeekMode) -> SeekMode -> Int # inRange :: (SeekMode, SeekMode) -> SeekMode -> Bool # rangeSize :: (SeekMode, SeekMode) -> Int # unsafeRangeSize :: (SeekMode, SeekMode) -> Int # | |
| Read SeekMode # | Since: base-4.2.0.0 |
| Show SeekMode # | Since: base-4.2.0.0 |
| Eq SeekMode # | Since: base-4.2.0.0 |
| Ord SeekMode # | Since: base-4.2.0.0 |
Defined in GHC.Internal.IO.Device | |
A space efficient, packed, unboxed Unicode text type.
Instances
| PrintfArg Text # | Since: text-1.2.2.0 |
Defined in Data.Text | |
| Binary Text # | Since: text-1.2.1.0 |
| NFData Text # | |
| Monoid Text # | |
| Semigroup Text # | Beware: Since: text-1.2.2.0 |
| Data Text # | This instance preserves data abstraction at the cost of inefficiency. We omit reflection services for the sake of data abstraction. This instance was created by copying the updated behavior of
The original discussion is archived here: could we get a Data instance for Data.Text.Text? The followup discussion that changed the behavior of |
Defined in Data.Text Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Text -> c Text # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Text # dataTypeOf :: Text -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Text) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Text) # gmapT :: (forall b. Data b => b -> b) -> Text -> Text # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Text -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Text -> r # gmapQ :: (forall d. Data d => d -> u) -> Text -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Text -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Text -> m Text # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Text -> m Text # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Text -> m Text # | |
| IsString Text # | Performs replacement on invalid scalar values:
|
Defined in Data.Text Methods fromString :: String -> Text # | |
| IsList Text # | Performs replacement on invalid scalar values:
Since: text-1.2.0.0 |
| Read Text # | |
| Show Text # | |
| Eq Text # | |
| Ord Text # | |
| Lift Text # | Since: text-1.2.4.0 |
| type Item Text # | |