fs-effectful
Safe HaskellNone
LanguageGHC2021

Effectful.FileSystem.HandleReader.Static

Description

Provides a static effect for reading a handle.

Since: 0.1

Synopsis

Effect

data HandleReader (a :: Type -> Type) b Source #

Static effect for reading a handle.

Since: 0.1

openBinaryFile :: forall (es :: [Effect]). (HandleReader :> es, HasCallStack) => OsPath -> Eff es (Handle 'HandleModeRead) Source #

Lifted openBinaryFile.

Since: 0.1

withBinaryFile :: forall (es :: [Effect]) a. (HandleReader :> es, HasCallStack) => OsPath -> (Handle 'HandleModeRead -> Eff es a) -> Eff es a Source #

Lifted withBinaryFile.

Since: 0.1

hIsEOF :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es Bool Source #

Lifted hIsEof.

Since: 0.1

hGetBuffering :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es BufferMode Source #

Lifted hGetBuffering.

Since: 0.1

hIsOpen :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es Bool Source #

Lifted hIsOpen.

Since: 0.1

hIsClosed :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es Bool Source #

Lifted hIsClosed.

Since: 0.1

hIsReadable :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es Bool Source #

Lifted hIsReadable.

Since: 0.1

hIsWritable :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es Bool Source #

Lifted hIsWritable.

Since: 0.1

hIsSeekable :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es Bool Source #

Lifted hIsSeekable.

Since: 0.1

hIsTerminalDevice :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es Bool Source #

Lifted hIsTerminalDevice.

Since: 0.1

hGetEcho :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es Bool Source #

Lifted hGetEcho.

Since: 0.1

hWaitForInput :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Int -> Eff es Bool Source #

Lifted hWaitForInput.

Since: 0.1

hReady :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es Bool Source #

Lifted hReady.

Since: 0.1

hGetChar :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es Char Source #

Lifted hGetChar.

Since: 0.1

hGetLine :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es ByteString Source #

Lifted hGetLine.

Since: 0.1

hGetContents :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es ByteString Source #

Lifted hGetContents.

Since: 0.1

hGet :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Int -> Eff es ByteString Source #

Lifted hGet.

Since: 0.1

hGetSome :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Int -> Eff es ByteString Source #

Lifted hGetSome.

Since: 0.1

hGetNonBlocking :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Int -> Eff es ByteString Source #

Lifted hGetNonBlocking.

Since: 0.1

hLockRaw :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es () Source #

Attempts to shared lock a file, blocking or throwing an exception upon failure.

Since: 0.1

hTryLockRaw :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es Bool Source #

Attempts to shared lock a file.

Since: 0.1

hUnlockRaw :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es () Source #

Unlocks a locked file.

Since: 0.1

Handlers

runHandleReader :: forall (es :: [Effect]) a. (HasCallStack, IOE :> es) => Eff (HandleReader ': es) a -> Eff es a Source #

Runs HandleReader 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

Instances details
HasField "unHandle" (Handle p :: Type) Handle Source #

Since: 0.1

Instance details

Defined in Effectful.FileSystem.Handle.Internal

Methods

getField :: Handle p -> Handle #

HasField "unLockedHandle" (LockedHandle p :: Type) (Handle p :: Type) Source #

Since: 0.1

Instance details

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

Instance details

Defined in Effectful.FileSystem.Handle.Internal

Methods

labelOptic :: Optic k NoIx (Handle p) (Handle p) a b Source #

data HandleMode Source #

Possible handle modes.

Since: 0.1

Constructors

HandleModeRead

Since: 0.1

type family CanRead (hm :: HandleMode) where ... Source #

Since: 0.1

Equations

CanRead 'HandleModeRead = () 
CanRead 'HandleModeWrite = Unsatisfiable ('Text "HandleModeWrite does not have Read permission.") 
CanRead 'HandleModeReadWrite = () 

Locking

These functions bring some type-safety to file locking. Consider:

main :: (HandleReader :> es) => Eff es ()
main = withBinaryFile path False $ \h -> do
  hLockRaw handle
  bs <- readBytes @HandleModeRead h
  hUnlockRaw handle
  print bs

readBytes :: (CanRead p, HandleReader :> es) => Handle p -> Eff es ByteString
readBytes handle = hGet handle 1024

In this example, we could remove all locking logic from main and everything would still compile. On the other hand:

main :: (HandleReader :> es) => Eff es ()
main = withBinaryFile path False $ \h -> withLockedFile h $ \lh -> do
  bs <- readBytes @HandleModeRead lh
  print bs

readBytes :: (CanRead p, HandleReader :> es) => LockedHandle p -> Eff es ByteString
readBytes lockedHandle = liftLocked (\h -> hGet h 1024) 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

Instances details
HasField "unLockedHandle" (LockedHandle p :: Type) (Handle p :: Type) Source #

Since: 0.1

Instance details

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

Instance details

Defined in Effectful.FileSystem.Handle.Internal

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

withLockedFile Source #

Arguments

:: forall (p :: HandleMode) (es :: [Effect]) a. (CanRead p, HandleReader :> es, HasCallStack) 
=> Handle p

Handle to lock.

-> (LockedHandle p -> Eff es a)

Callback with locked handle.

-> Eff es a 

Runs a computation with a shared locked file.

Since: 0.1

withTryLockedFile Source #

Arguments

:: forall (p :: HandleMode) a (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) 
=> 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

hLock Source #

Arguments

:: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) 
=> Handle p

Handle to lock.

-> Eff es (LockedHandle p) 

Like hLockRaw, but returns a LockedHandle.

Since: 0.1

hTryLock Source #

Arguments

:: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) 
=> Handle p

Handle to lock.

-> Eff es (Maybe (LockedHandle p)) 

Like hTryLockRaw, but returns a LockedHandle if it succeeds.

Since: 0.1

hUnlock Source #

Arguments

:: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) 
=> LockedHandle p

Handle to unlock.

-> Eff es (Handle p) 

Like hUnlockRaw, but returns the original handle.

Since: 0.1

Raw

withLockedFileRaw Source #

Arguments

:: forall (p :: HandleMode) (es :: [Effect]) a. (CanRead p, HandleReader :> es, HasCallStack) 
=> Handle p

Handle to lock.

-> Eff es a

Callback with locked handle.

-> Eff es a 

withLockedFile without LockedHandle.

Since: 0.1

withTryLockedFileRaw Source #

Arguments

:: forall (p :: HandleMode) a (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) 
=> Handle p

Handle to lock.

-> Eff es a

Handle callback.

-> Eff es (Maybe a) 

UTF-8 Utils

GetLine

hGetLineUtf8ThrowM :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Eff es Text Source #

hGetLine and decodeUtf8ThrowM.

Since: 0.1

GetContents

Get

hGetUtf8 :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Int -> Eff es (Either UnicodeException Text) Source #

hGet and decodeUtf8.

Since: 0.1

hGetUtf8Lenient :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Int -> Eff es Text Source #

hGet and decodeUtf8Lenient.

Since: 0.1

hGetUtf8ThrowM :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Int -> Eff es Text Source #

hGet and decodeUtf8ThrowM.

Since: 0.1

GetSome

hGetSomeUtf8 :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Int -> Eff es (Either UnicodeException Text) Source #

hGetSome and decodeUtf8.

Since: 0.1

hGetSomeUtf8Lenient :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Int -> Eff es Text Source #

hGetSomeUtf8ThrowM :: forall (p :: HandleMode) (es :: [Effect]). (CanRead p, HandleReader :> es, HasCallStack) => Handle p -> Int -> Eff es Text Source #

hGetSome and decodeUtf8ThrowM.

Since: 0.1

GetNonBlocking

Re-exports

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

Instances details
NFData ByteString # 
Instance details

Defined in Data.ByteString.Internal.Type

Methods

rnf :: ByteString -> () #

Monoid ByteString # 
Instance details

Defined in Data.ByteString.Internal.Type

Semigroup ByteString # 
Instance details

Defined in Data.ByteString.Internal.Type

Data ByteString # 
Instance details

Defined in Data.ByteString.Internal.Type

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ByteString -> c ByteString #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ByteString #

toConstr :: ByteString -> Constr #

dataTypeOf :: ByteString -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ByteString) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ByteString) #

gmapT :: (forall b. Data b => b -> b) -> ByteString -> ByteString #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ByteString -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ByteString -> r #

gmapQ :: (forall d. Data d => d -> u) -> ByteString -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ByteString -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ByteString -> m ByteString #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteString -> m ByteString #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteString -> m ByteString #

IsString ByteString #

Beware: fromString truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�

Instance details

Defined in Data.ByteString.Internal.Type

IsList ByteString #

Since: bytestring-0.10.12.0

Instance details

Defined in Data.ByteString.Internal.Type

Associated Types

type Item ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Read ByteString # 
Instance details

Defined in Data.ByteString.Internal.Type

Show ByteString # 
Instance details

Defined in Data.ByteString.Internal.Type

Eq ByteString # 
Instance details

Defined in Data.ByteString.Internal.Type

Ord ByteString # 
Instance details

Defined in Data.ByteString.Internal.Type

Lift ByteString #

Since: bytestring-0.11.2.0

Instance details

Defined in Data.ByteString.Internal.Type

Methods

lift :: Quote m => ByteString -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => ByteString -> Code m ByteString #

type Item ByteString # 
Instance details

Defined in Data.ByteString.Internal.Type

type OsPath = OsString #

Type representing filenames/pathnames.

This type doesn't add any guarantees over OsString.

data Text #

A space efficient, packed, unboxed Unicode text type.

Instances

Instances details
PrintfArg Text #

Since: text-1.2.2.0

Instance details

Defined in Data.Text

Binary Text #

Since: text-1.2.1.0

Instance details

Defined in Data.Text

Methods

put :: Text -> Put #

get :: Get Text #

putList :: [Text] -> Put #

NFData Text # 
Instance details

Defined in Data.Text

Methods

rnf :: Text -> () #

Monoid Text # 
Instance details

Defined in Data.Text

Methods

mempty :: Text #

mappend :: Text -> Text -> Text #

mconcat :: [Text] -> Text #

Semigroup Text #

Beware: stimes will crash if the given number does not fit into an Int.

Since: text-1.2.2.0

Instance details

Defined in Data.Text

Methods

(<>) :: Text -> Text -> Text #

sconcat :: NonEmpty Text -> Text #

stimes :: Integral b => b -> Text -> Text #

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 Data.Set.Set and Data.Map.Map. If you feel a mistake has been made, please feel free to submit improvements.

The original discussion is archived here: could we get a Data instance for Data.Text.Text?

The followup discussion that changed the behavior of Set and Map is archived here: Proposal: Allow gunfold for Data.Map, ...

Instance details

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 #

toConstr :: Text -> Constr #

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:

>>> :set -XOverloadedStrings
>>> "\55555" :: Text
"\65533"
Instance details

Defined in Data.Text

Methods

fromString :: String -> Text #

IsList Text #

Performs replacement on invalid scalar values:

>>> :set -XOverloadedLists
>>> ['\55555'] :: Text
"\65533"

Since: text-1.2.0.0

Instance details

Defined in Data.Text

Associated Types

type Item Text 
Instance details

Defined in Data.Text

type Item Text = Char

Methods

fromList :: [Item Text] -> Text #

fromListN :: Int -> [Item Text] -> Text #

toList :: Text -> [Item Text] #

Read Text # 
Instance details

Defined in Data.Text

Show Text # 
Instance details

Defined in Data.Text.Show

Methods

showsPrec :: Int -> Text -> ShowS #

show :: Text -> String #

showList :: [Text] -> ShowS #

Eq Text # 
Instance details

Defined in Data.Text

Methods

(==) :: Text -> Text -> Bool #

(/=) :: Text -> Text -> Bool #

Ord Text # 
Instance details

Defined in Data.Text

Methods

compare :: Text -> Text -> Ordering #

(<) :: Text -> Text -> Bool #

(<=) :: Text -> Text -> Bool #

(>) :: Text -> Text -> Bool #

(>=) :: Text -> Text -> Bool #

max :: Text -> Text -> Text #

min :: Text -> Text -> Text #

Lift Text #

Since: text-1.2.4.0

Instance details

Defined in Data.Text

Methods

lift :: Quote m => Text -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => Text -> Code m Text #

type Item Text # 
Instance details

Defined in Data.Text

type Item Text = Char