fused-effects-0.1.2.1: A fast, flexible, fused effect system.

Safe HaskellNone
LanguageHaskell2010

Control.Effect.Resource

Synopsis

Documentation

data Resource m k Source #

Constructors

Resource (m resource) (resource -> m any) (resource -> m output) (output -> k) 
Instances
Effect Resource Source # 
Instance details

Defined in Control.Effect.Resource

Methods

handle :: Functor f => f () -> (forall x. f (m x) -> n (f x)) -> Resource m (m a) -> Resource n (n (f a)) Source #

HFunctor Resource Source # 
Instance details

Defined in Control.Effect.Resource

Methods

fmap' :: (a -> b) -> Resource m a -> Resource m b Source #

hmap :: (forall x. m x -> n x) -> Resource m a -> Resource n a Source #

Functor (Resource m) Source # 
Instance details

Defined in Control.Effect.Resource

Methods

fmap :: (a -> b) -> Resource m a -> Resource m b #

(<$) :: a -> Resource m b -> Resource m a #

(Carrier sig m, MonadIO m) => Carrier (Resource :+: sig) (ResourceC m) Source # 
Instance details

Defined in Control.Effect.Resource

Methods

ret :: a -> ResourceC m a Source #

eff :: (Resource :+: sig) (ResourceC m) (ResourceC m a) -> ResourceC m a Source #

bracket Source #

Arguments

:: (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 #

newtype ResourceC m a Source #

Constructors

ResourceC ((forall x. m x -> IO x) -> m a) 
Instances
(Carrier sig m, MonadIO m) => Carrier (Resource :+: sig) (ResourceC m) Source # 
Instance details

Defined in Control.Effect.Resource

Methods

ret :: a -> ResourceC m a Source #

eff :: (Resource :+: sig) (ResourceC m) (ResourceC m a) -> ResourceC m a Source #