Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
The Scoped
monad to safely allocate and deallocate resources.
Synopsis
- data Scoped s m a
- data ScopedResource s a
- scoped :: forall m a. Applicative m => (forall s. Scoped s m a) -> m a
- registerHandler :: MonadUnliftIO m => m a -> Scoped s m ()
- type ScopedAsync s a = ScopedResource s (Async a)
- async :: MonadUnliftIO m => m a -> Scoped s m (ScopedAsync s a)
- asyncBound :: MonadUnliftIO m => m a -> Scoped s m (ScopedAsync s a)
- wait :: MonadIO m => ScopedAsync s a -> Scoped s m a
- waitCatch :: MonadIO m => ScopedAsync s a -> Scoped s m (Either SomeException a)
- waitScoped :: MonadUnliftIO m => ScopedAsync s a -> Scoped s m ()
- waitCatchScoped :: MonadUnliftIO m => ScopedAsync s a -> Scoped s m ()
- type ScopedHandle s = ScopedResource s Handle
- file :: MonadUnliftIO m => FilePath -> IOMode -> Scoped s m (ScopedHandle s)
- data IOMode
- hPutStrLn :: MonadIO m => ScopedHandle s -> Text -> Scoped s m ()
- hPutStr :: MonadIO m => ScopedHandle s -> Text -> Scoped s m ()
- hGetLine :: MonadIO m => ScopedHandle s -> Scoped s m Text
- hGetContents :: MonadIO m => ScopedHandle s -> Scoped s m Text
- tempFile :: MonadUnliftIO m => FilePath -> String -> Scoped s m (FilePath, ScopedHandle s)
- systemTempFile :: MonadUnliftIO m => String -> Scoped s m (FilePath, ScopedHandle s)
Scoped
computations and ScopedResource
s
The Scoped
monad that provides the possibility to safely scope the allocation of a resource
It is used to abstract over all of the CPS style withSomething functions, like withFile
Be sure to properly mask handlers if you are using UnsafeMkScoped
. Use safe helper functions like
registerHandler
or bracketScoped
where possible.
Instances
MonadTrans (Scoped s :: (Type -> Type) -> Type -> Type) Source # | |
Defined in Control.Monad.Scoped.Internal | |
MonadFail m => MonadFail (Scoped s m) Source # | |
Defined in Control.Monad.Scoped.Internal | |
MonadIO m => MonadIO (Scoped s m) Source # | You can perform |
Defined in Control.Monad.Scoped.Internal | |
Alternative m => Alternative (Scoped s m) Source # | |
Applicative (Scoped s m) Source # | |
Defined in Control.Monad.Scoped.Internal | |
Functor (Scoped s m) Source # | |
Monad (Scoped s m) Source # | |
Alternative m => MonadPlus (Scoped s m) Source # | |
data ScopedResource s a Source #
A scoped resource with token s
belonging to a Scoped
block with the same token.
If you are creating a ScopedResource
, make sure the resource is deallocated properly
when the Scoped
block is exited.
Instances
Show a => Show (ScopedResource s a) Source # | |
Defined in Control.Monad.Scoped.Internal showsPrec :: Int -> ScopedResource s a -> ShowS # show :: ScopedResource s a -> String # showList :: [ScopedResource s a] -> ShowS # | |
Eq a => Eq (ScopedResource s a) Source # | |
Defined in Control.Monad.Scoped.Internal (==) :: ScopedResource s a -> ScopedResource s a -> Bool # (/=) :: ScopedResource s a -> ScopedResource s a -> Bool # | |
Ord a => Ord (ScopedResource s a) Source # | |
Defined in Control.Monad.Scoped.Internal compare :: ScopedResource s a -> ScopedResource s a -> Ordering # (<) :: ScopedResource s a -> ScopedResource s a -> Bool # (<=) :: ScopedResource s a -> ScopedResource s a -> Bool # (>) :: ScopedResource s a -> ScopedResource s a -> Bool # (>=) :: ScopedResource s a -> ScopedResource s a -> Bool # max :: ScopedResource s a -> ScopedResource s a -> ScopedResource s a # min :: ScopedResource s a -> ScopedResource s a -> ScopedResource s a # |
Safely work with scopes
:: forall m a. Applicative m | |
=> (forall s. Scoped s m a) | the scoped computation to be run |
-> m a |
:: MonadUnliftIO m | |
=> m a | the handler to be registered |
-> Scoped s m () |
Safely work with Async
s
type ScopedAsync s a = ScopedResource s (Async a) Source #
async :: MonadUnliftIO m => m a -> Scoped s m (ScopedAsync s a) Source #
asyncBound :: MonadUnliftIO m => m a -> Scoped s m (ScopedAsync s a) Source #
wait :: MonadIO m => ScopedAsync s a -> Scoped s m a Source #
Wait for the ScopedAsync
to finish immediately
waitCatch :: MonadIO m => ScopedAsync s a -> Scoped s m (Either SomeException a) Source #
Like wait
but return either
or Left
SomeException
Right
a
waitScoped :: MonadUnliftIO m => ScopedAsync s a -> Scoped s m () Source #
waitCatchScoped :: MonadUnliftIO m => ScopedAsync s a -> Scoped s m () Source #
Safely work with Handle
s
type ScopedHandle s = ScopedResource s Handle Source #
file :: MonadUnliftIO m => FilePath -> IOMode -> Scoped s m (ScopedHandle s) Source #
Given a FilePath
, safely allocates and deallocates a ScopedHandle
in a Scoped
block
See openFile
hPutStrLn :: MonadIO m => ScopedHandle s -> Text -> Scoped s m () Source #
Like hPutStrLn
but for ScopedHandle
hPutStr :: MonadIO m => ScopedHandle s -> Text -> Scoped s m () Source #
Like hPutStr
but for ScopedHandle
hGetLine :: MonadIO m => ScopedHandle s -> Scoped s m Text Source #
Like hGetLine
but for ScopedHandle
hGetContents :: MonadIO m => ScopedHandle s -> Scoped s m Text Source #
Like hGetContents
but for ScopedHandle
Safely work with tempfiles
tempFile :: MonadUnliftIO m => FilePath -> String -> Scoped s m (FilePath, ScopedHandle s) Source #
Like withTempFile
but for Scoped
systemTempFile :: MonadUnliftIO m => String -> Scoped s m (FilePath, ScopedHandle s) Source #
Like withSystemTempFile
but for Scoped