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, Applicative m) => m a -> m b -> m a
- onException :: (Member Resource sig, Carrier sig m, Applicative m) => m a -> m b -> m a
- runResource :: (Carrier sig m, MonadIO m) => (forall x. m x -> IO x) -> Eff (ResourceC m) a -> m a
- newtype ResourceC m a = ResourceC ((forall x. m x -> IO x) -> 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, Applicative 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, Applicative 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.
runResource :: (Carrier sig m, MonadIO m) => (forall x. m x -> IO x) -> Eff (ResourceC m) a -> m a Source #