{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module Effectful.FileSystem.HandleWriter.Static
(
HandleWriter,
openBinaryFile,
withBinaryFile,
hClose,
hFlush,
hSetFileSize,
hSetBuffering,
hSeek,
hTell,
hSetEcho,
hPut,
hPutNonBlocking,
hLockRaw,
hTryLockRaw,
hUnlockRaw,
runHandleWriter,
Handle,
HandleMode (HandleModeWrite),
CanWrite,
LockedHandle,
Internal.liftLocked,
withLockedFile,
withTryLockedFile,
hLock,
hTryLock,
hUnlock,
withLockedFileRaw,
withTryLockedFileRaw,
hPutUtf8,
hPutNonBlockingUtf8,
die,
BufferMode (..),
ByteString,
IOMode (..),
OsPath,
SeekMode (..),
Text,
)
where
import Control.Exception.Utils (exitFailure)
import Data.ByteString (ByteString)
import Data.ByteString qualified as BS
import Data.ByteString.Char8 qualified as Char8
import Data.Text (Text)
import Effectful
( Dispatch (Static),
DispatchOf,
Eff,
Effect,
IOE,
type (:>),
)
import Effectful.Dispatch.Static
( HasCallStack,
SideEffects (WithSideEffects),
StaticRep,
evalStaticRep,
seqUnliftIO,
unsafeEff,
unsafeEff_,
)
import Effectful.Exception (bracket, bracket_)
import Effectful.FileSystem.Handle qualified as Handle
import Effectful.FileSystem.Handle.Internal
( CanWrite,
Handle (MkHandle),
HandleMode (HandleModeWrite),
LockedHandle,
)
import Effectful.FileSystem.Handle.Internal qualified as Internal
import FileSystem.IO (openBinaryFileIO, withBinaryFileIO)
import FileSystem.OsPath (OsPath)
import FileSystem.UTF8 qualified as FS.UTF8
import GHC.IO.Handle.Lock qualified as Lock
import System.IO
( BufferMode (BlockBuffering, LineBuffering, NoBuffering),
IOMode (AppendMode, ReadMode, ReadWriteMode, WriteMode),
SeekMode (AbsoluteSeek, RelativeSeek, SeekFromEnd),
)
import System.IO qualified as IO
data HandleWriter :: Effect
type instance DispatchOf HandleWriter = Static WithSideEffects
data instance StaticRep HandleWriter = MkHandleWriter
runHandleWriter ::
(HasCallStack, IOE :> es) =>
Eff (HandleWriter : es) a ->
Eff es a
runHandleWriter :: forall (es :: [Effect]) a.
(HasCallStack, IOE :> es) =>
Eff (HandleWriter : es) a -> Eff es a
runHandleWriter = StaticRep HandleWriter -> Eff (HandleWriter : es) a -> Eff es a
forall (e :: Effect) (sideEffects :: SideEffects) (es :: [Effect])
a.
(HasCallStack, DispatchOf e ~ 'Static sideEffects,
MaybeIOE sideEffects es) =>
StaticRep e -> Eff (e : es) a -> Eff es a
evalStaticRep StaticRep HandleWriter
MkHandleWriter
openBinaryFile ::
( HandleWriter :> es,
HasCallStack
) =>
OsPath ->
Bool ->
Eff es (Handle HandleModeWrite)
openBinaryFile :: forall (es :: [Effect]).
(HandleWriter :> es, HasCallStack) =>
OsPath -> Bool -> Eff es (Handle 'HandleModeWrite)
openBinaryFile OsPath
p =
IO (Handle 'HandleModeWrite) -> Eff es (Handle 'HandleModeWrite)
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_
(IO (Handle 'HandleModeWrite) -> Eff es (Handle 'HandleModeWrite))
-> (Bool -> IO (Handle 'HandleModeWrite))
-> Bool
-> Eff es (Handle 'HandleModeWrite)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Handle -> Handle 'HandleModeWrite)
-> IO Handle -> IO (Handle 'HandleModeWrite)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Handle -> Handle 'HandleModeWrite
forall (p :: HandleMode). Handle -> Handle p
MkHandle
(IO Handle -> IO (Handle 'HandleModeWrite))
-> (Bool -> IO Handle) -> Bool -> IO (Handle 'HandleModeWrite)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OsPath -> IOMode -> IO Handle
openBinaryFileIO OsPath
p
(IOMode -> IO Handle) -> (Bool -> IOMode) -> Bool -> IO Handle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> IOMode
Internal.appendToMode
withBinaryFile ::
forall es a.
( HandleWriter :> es,
HasCallStack
) =>
OsPath ->
Bool ->
(Handle HandleModeWrite -> Eff es a) ->
Eff es a
withBinaryFile :: forall (es :: [Effect]) a.
(HandleWriter :> es, HasCallStack) =>
OsPath -> Bool -> (Handle 'HandleModeWrite -> Eff es a) -> Eff es a
withBinaryFile OsPath
p Bool
append Handle 'HandleModeWrite -> Eff es a
onHandle =
(Env es -> IO a) -> Eff es a
forall (es :: [Effect]) a. (Env es -> IO a) -> Eff es a
unsafeEff ((Env es -> IO a) -> Eff es a) -> (Env es -> IO a) -> Eff es a
forall a b. (a -> b) -> a -> b
$ \Env es
env -> Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall (es :: [Effect]) a.
HasCallStack =>
Env es -> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
seqUnliftIO Env es
env (((forall r. Eff es r -> IO r) -> IO a) -> IO a)
-> ((forall r. Eff es r -> IO r) -> IO a) -> IO a
forall a b. (a -> b) -> a -> b
$ \forall r. Eff es r -> IO r
runInIO ->
OsPath -> IOMode -> (Handle -> IO a) -> IO a
forall a. OsPath -> IOMode -> (Handle -> IO a) -> IO a
withBinaryFileIO
OsPath
p
(Bool -> IOMode
Internal.appendToMode Bool
append)
(Eff es a -> IO a
forall r. Eff es r -> IO r
runInIO (Eff es a -> IO a) -> (Handle -> Eff es a) -> Handle -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle 'HandleModeWrite -> Eff es a
onHandle (Handle 'HandleModeWrite -> Eff es a)
-> (Handle -> Handle 'HandleModeWrite) -> Handle -> Eff es a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Handle 'HandleModeWrite
forall (p :: HandleMode). Handle -> Handle p
MkHandle)
hClose ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p ->
Eff es ()
hClose :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es ()
hClose = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> (Handle p -> IO ()) -> Handle p -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO ()
IO.hClose (Handle -> IO ()) -> (Handle p -> Handle) -> Handle p -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle
hFlush ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p ->
Eff es ()
hFlush :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es ()
hFlush = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> (Handle p -> IO ()) -> Handle p -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO ()
IO.hFlush (Handle -> IO ()) -> (Handle p -> Handle) -> Handle p -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle
hSetFileSize ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p ->
Integer ->
Eff es ()
hSetFileSize :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Integer -> Eff es ()
hSetFileSize Handle p
h = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ()) -> (Integer -> IO ()) -> Integer -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Integer -> IO ()
IO.hSetFileSize (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h)
hSetBuffering ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p ->
BufferMode ->
Eff es ()
hSetBuffering :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> BufferMode -> Eff es ()
hSetBuffering Handle p
h = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> (BufferMode -> IO ()) -> BufferMode -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> BufferMode -> IO ()
IO.hSetBuffering (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h)
hSeek ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p ->
SeekMode ->
Integer ->
Eff es ()
hSeek :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> SeekMode -> Integer -> Eff es ()
hSeek Handle p
h SeekMode
m = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ()) -> (Integer -> IO ()) -> Integer -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> SeekMode -> Integer -> IO ()
IO.hSeek (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h) SeekMode
m
hTell ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p ->
Eff es Integer
hTell :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es Integer
hTell = IO Integer -> Eff es Integer
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Integer -> Eff es Integer)
-> (Handle p -> IO Integer) -> Handle p -> Eff es Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO Integer
IO.hTell (Handle -> IO Integer)
-> (Handle p -> Handle) -> Handle p -> IO Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle
hSetEcho ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p ->
Bool ->
Eff es ()
hSetEcho :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Bool -> Eff es ()
hSetEcho Handle p
h = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ()) -> (Bool -> IO ()) -> Bool -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> Bool -> IO ()
IO.hSetEcho (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h)
hPut ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p ->
ByteString ->
Eff es ()
hPut :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> ByteString -> Eff es ()
hPut Handle p
h = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> (ByteString -> IO ()) -> ByteString -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ()
BS.hPut (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h)
hPutNonBlocking ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p ->
ByteString ->
Eff es ByteString
hPutNonBlocking :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> ByteString -> Eff es ByteString
hPutNonBlocking Handle p
h = IO ByteString -> Eff es ByteString
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO ByteString -> Eff es ByteString)
-> (ByteString -> IO ByteString) -> ByteString -> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> ByteString -> IO ByteString
BS.hPutNonBlocking (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h)
hLockRaw ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p -> Eff es ()
hLockRaw :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es ()
hLockRaw Handle p
h = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ()) -> IO () -> Eff es ()
forall a b. (a -> b) -> a -> b
$ Handle -> LockMode -> IO ()
Lock.hLock (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h) LockMode
Lock.ExclusiveLock
hTryLockRaw ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p -> Eff es Bool
hTryLockRaw :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es Bool
hTryLockRaw Handle p
h = IO Bool -> Eff es Bool
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO Bool -> Eff es Bool) -> IO Bool -> Eff es Bool
forall a b. (a -> b) -> a -> b
$ Handle -> LockMode -> IO Bool
Lock.hTryLock (Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle Handle p
h) LockMode
Lock.ExclusiveLock
hUnlockRaw ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p -> Eff es ()
hUnlockRaw :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw = IO () -> Eff es ()
forall a (es :: [Effect]). IO a -> Eff es a
unsafeEff_ (IO () -> Eff es ())
-> (Handle p -> IO ()) -> Handle p -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle -> IO ()
Lock.hUnlock (Handle -> IO ()) -> (Handle p -> Handle) -> Handle p -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Handle p -> Handle
forall (p :: HandleMode). Handle p -> Handle
Internal.unHandle
hLock ::
( CanWrite p,
HasCallStack,
HandleWriter :> es
) =>
Handle p ->
Eff es (LockedHandle p)
hLock :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HasCallStack, HandleWriter :> es) =>
Handle p -> Eff es (LockedHandle p)
hLock = (Handle p -> Eff es ()) -> Handle p -> Eff es (LockedHandle p)
forall (f :: * -> *) (p :: HandleMode).
Functor f =>
(Handle p -> f ()) -> Handle p -> f (LockedHandle p)
Internal.liftLock Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es ()
hLockRaw
hTryLock ::
( CanWrite p,
HasCallStack,
HandleWriter :> es
) =>
Handle p ->
Eff es (Maybe (LockedHandle p))
hTryLock :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HasCallStack, HandleWriter :> es) =>
Handle p -> Eff es (Maybe (LockedHandle p))
hTryLock = (Handle p -> Eff es Bool)
-> Handle p -> Eff es (Maybe (LockedHandle p))
forall (f :: * -> *) (p :: HandleMode).
Functor f =>
(Handle p -> f Bool) -> Handle p -> f (Maybe (LockedHandle p))
Internal.liftTryLock Handle p -> Eff es Bool
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es Bool
hTryLockRaw
hUnlock ::
( CanWrite p,
HasCallStack,
HandleWriter :> es
) =>
LockedHandle p ->
Eff es (Handle p)
hUnlock :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HasCallStack, HandleWriter :> es) =>
LockedHandle p -> Eff es (Handle p)
hUnlock = (Handle p -> Eff es ()) -> LockedHandle p -> Eff es (Handle p)
forall (f :: * -> *) (p :: HandleMode).
Functor f =>
(Handle p -> f ()) -> LockedHandle p -> f (Handle p)
Internal.liftUnlock Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw
withLockedFile ::
( CanWrite p,
HasCallStack,
HandleWriter :> es
) =>
Handle p ->
(LockedHandle p -> Eff es a) ->
Eff es a
withLockedFile :: forall (p :: HandleMode) (es :: [Effect]) a.
(CanWrite p, HasCallStack, HandleWriter :> es) =>
Handle p -> (LockedHandle p -> Eff es a) -> Eff es a
withLockedFile = (Handle p -> Eff es ())
-> (Handle p -> Eff es ())
-> Handle p
-> (LockedHandle p -> Eff es a)
-> Eff es a
forall (p :: HandleMode) (es :: [Effect]) a.
HasCallStack =>
(Handle p -> Eff es ())
-> (Handle p -> Eff es ())
-> Handle p
-> (LockedHandle p -> Eff es a)
-> Eff es a
Internal.withLockedFile Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es ()
hLockRaw Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw
withTryLockedFile ::
forall p a es.
( CanWrite p,
HasCallStack,
HandleWriter :> es
) =>
Handle p ->
(LockedHandle p -> Eff es a) ->
Eff es (Maybe a)
withTryLockedFile :: forall (p :: HandleMode) a (es :: [Effect]).
(CanWrite p, HasCallStack, HandleWriter :> es) =>
Handle p -> (LockedHandle p -> Eff es a) -> Eff es (Maybe a)
withTryLockedFile = (Handle p -> Eff es Bool)
-> (Handle p -> Eff es ())
-> Handle p
-> (LockedHandle p -> Eff es a)
-> Eff es (Maybe a)
forall (p :: HandleMode) a (es :: [Effect]).
HasCallStack =>
(Handle p -> Eff es Bool)
-> (Handle p -> Eff es ())
-> Handle p
-> (LockedHandle p -> Eff es a)
-> Eff es (Maybe a)
Internal.withTryLockedFile Handle p -> Eff es Bool
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es Bool
hTryLockRaw Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw
withLockedFileRaw ::
( CanWrite p,
HasCallStack,
HandleWriter :> es
) =>
Handle p ->
Eff es a ->
Eff es a
withLockedFileRaw :: forall (p :: HandleMode) (es :: [Effect]) a.
(CanWrite p, HasCallStack, HandleWriter :> es) =>
Handle p -> Eff es a -> Eff es a
withLockedFileRaw Handle p
h = Eff es () -> Eff es () -> Eff es a -> Eff es a
forall (es :: [Effect]) a b c.
Eff es a -> Eff es b -> Eff es c -> Eff es c
bracket_ (Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es ()
hLockRaw Handle p
h) (Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw Handle p
h)
withTryLockedFileRaw ::
forall p a es.
( CanWrite p,
HasCallStack,
HandleWriter :> es
) =>
Handle p ->
Eff es a ->
Eff es (Maybe a)
withTryLockedFileRaw :: forall (p :: HandleMode) a (es :: [Effect]).
(CanWrite p, HasCallStack, HandleWriter :> es) =>
Handle p -> Eff es a -> Eff es (Maybe a)
withTryLockedFileRaw Handle p
h Eff es a
m =
Eff es (Maybe ())
-> (Maybe () -> Eff es (Maybe ()))
-> (Maybe () -> Eff es (Maybe a))
-> Eff es (Maybe a)
forall (es :: [Effect]) a b c.
Eff es a -> (a -> Eff es b) -> (a -> Eff es c) -> Eff es c
bracket
( do
locked <- Handle p -> Eff es Bool
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es Bool
hTryLockRaw Handle p
h
pure $
if locked
then Just ()
else Nothing
)
((() -> Eff es ()) -> Maybe () -> Eff es (Maybe ())
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse (Eff es () -> () -> Eff es ()
forall a b. a -> b -> a
const (Handle p -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Eff es ()
hUnlockRaw Handle p
h)))
((() -> Eff es a) -> Maybe () -> Eff es (Maybe a)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse (Eff es a -> () -> Eff es a
forall a b. a -> b -> a
const Eff es a
m))
hPutUtf8 ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p ->
Text ->
Eff es ()
hPutUtf8 :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Text -> Eff es ()
hPutUtf8 Handle p
h = Handle p -> ByteString -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> ByteString -> Eff es ()
hPut Handle p
h (ByteString -> Eff es ())
-> (Text -> ByteString) -> Text -> Eff es ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
FS.UTF8.encodeUtf8
hPutNonBlockingUtf8 ::
( CanWrite p,
HandleWriter :> es,
HasCallStack
) =>
Handle p ->
Text ->
Eff es ByteString
hPutNonBlockingUtf8 :: forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> Text -> Eff es ByteString
hPutNonBlockingUtf8 Handle p
h = Handle p -> ByteString -> Eff es ByteString
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> ByteString -> Eff es ByteString
hPutNonBlocking Handle p
h (ByteString -> Eff es ByteString)
-> (Text -> ByteString) -> Text -> Eff es ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ByteString
FS.UTF8.encodeUtf8
die ::
( HandleWriter :> es,
HasCallStack
) =>
String ->
Eff es a
die :: forall (es :: [Effect]) a.
(HandleWriter :> es, HasCallStack) =>
String -> Eff es a
die String
err = Handle 'HandleModeReadWrite -> ByteString -> Eff es ()
forall (p :: HandleMode) (es :: [Effect]).
(CanWrite p, HandleWriter :> es, HasCallStack) =>
Handle p -> ByteString -> Eff es ()
hPut Handle 'HandleModeReadWrite
Handle.stderr ByteString
err' Eff es () -> Eff es a -> Eff es a
forall a b. Eff es a -> Eff es b -> Eff es b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Eff es a
forall (m :: * -> *) a. (HasCallStack, MonadThrow m) => m a
exitFailure
where
err' :: ByteString
err' = String -> ByteString
Char8.pack String
err