Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Resource m k = Resource (m resource) (resource -> m any) (resource -> m output) (output -> k)
- bracket :: (Member Resource sig, Carrier sig m) => m resource -> (resource -> m any) -> (resource -> m a) -> 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) |
:: (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.
runResource :: (Carrier sig m, MonadIO m) => (forall x. m x -> IO x) -> Eff (ResourceC m) a -> m a Source #