Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Resource m k
- bracket :: (Member Resource sig, Carrier sig m) => m resource -> (resource -> m any) -> (resource -> m a) -> m a
- bracketOnError :: (Member Resource sig, Carrier sig m) => m resource -> (resource -> m any) -> (resource -> m a) -> m a
- finally :: (Member Resource sig, Carrier sig m) => m a -> m b -> m a
- onException :: (Member Resource sig, Carrier sig m) => m a -> m b -> m a
- runResource :: (forall x. m x -> IO x) -> ResourceC m a -> m a
- withResource :: MonadUnliftIO m => ResourceC m a -> m a
- newtype ResourceC m a = ResourceC {
- runResourceC :: ReaderC (Handler m) m a
Documentation
Resource (m resource) (resource -> m any) (resource -> m output) (output -> k) | |
OnError (m resource) (resource -> m any) (resource -> m output) (output -> k) |
:: (Member Resource sig, Carrier sig m) | |
=> m resource | computation to run first ("acquire resource") |
-> (resource -> m any) | computation to run last ("release resource") |
-> (resource -> m a) | computation to run in-between |
-> m a |
Provides a safe idiom to acquire and release resources safely.
When acquiring and operating on a resource (such as opening and
reading file handle with openFile
or writing to a blob of memory
with malloc
), any exception thrown during the operation may mean
that the resource is not properly released. bracket acquire release op
ensures that release
is run on the value returned from acquire
even
if op
throws an exception.
bracket
is safe in the presence of asynchronous exceptions.
:: (Member Resource sig, Carrier sig m) | |
=> m resource | computation to run first ("acquire resource") |
-> (resource -> m any) | computation to run last ("release resource") |
-> (resource -> m a) | computation to run in-between |
-> m a |
Like bracket
, but only performs the final action if there was an
exception raised by the in-between computation.
:: (Member Resource sig, Carrier sig m) | |
=> m a | computation to run first |
-> m b | computation to run afterward (even if an exception was raised) |
-> m a |
Like bracket
, but for the simple case of one computation to run afterward.
:: (Member Resource sig, Carrier sig m) | |
=> m a | computation to run first |
-> m b | computation to run afterward if an exception was raised |
-> m a |
Like bracketOnError
, but for the simple case of one computation to run afterward.
withResource :: MonadUnliftIO m => ResourceC m a -> m a Source #
A helper for runResource
that uses withRunInIO
to automatically
select a correct unlifting function.
newtype ResourceC m a Source #
ResourceC | |
|
Instances
MonadTrans ResourceC Source # | |
Defined in Control.Effect.Resource | |
Monad m => Monad (ResourceC m) Source # | |
Functor m => Functor (ResourceC m) Source # | |
MonadFail m => MonadFail (ResourceC m) Source # | |
Defined in Control.Effect.Resource | |
Applicative m => Applicative (ResourceC m) Source # | |
Defined in Control.Effect.Resource | |
MonadIO m => MonadIO (ResourceC m) Source # | |
Defined in Control.Effect.Resource | |
Alternative m => Alternative (ResourceC m) Source # | |
(Alternative m, Monad m) => MonadPlus (ResourceC m) Source # | |
MonadUnliftIO m => MonadUnliftIO (ResourceC m) Source # | |
Defined in Control.Effect.Resource askUnliftIO :: ResourceC m (UnliftIO (ResourceC m)) withRunInIO :: ((forall a. ResourceC m a -> IO a) -> IO b) -> ResourceC m b | |
(Carrier sig m, MonadIO m) => Carrier (Resource :+: sig) (ResourceC m) Source # | |