polysemy-0.7.0.0: Higher-order, low-boilerplate, zero-cost free monads.

Safe HaskellNone
LanguageHaskell2010

Polysemy.Resource

Contents

Synopsis

Effect

data Resource m a where Source #

An effect capable of providing bracket semantics. Interpreters for this will successfully run the deallocation action even in the presence of other short-circuiting effects.

Constructors

Bracket :: m a -> (a -> m c) -> (a -> m b) -> Resource m b 
BracketOnError :: m a -> (a -> m c) -> (a -> m b) -> Resource m b 
Instances
type DefiningModule Resource Source # 
Instance details

Defined in Polysemy.Resource

type DefiningModule Resource = "Polysemy.Resource"

Actions

bracket :: forall r a c a. MemberWithError Resource r => Sem r a -> (a -> Sem r c) -> (a -> Sem r a) -> Sem r a Source #

bracketOnError :: forall r a c a. MemberWithError Resource r => Sem r a -> (a -> Sem r c) -> (a -> Sem r a) -> Sem r a Source #

finally Source #

Arguments

:: Member Resource r 
=> Sem r a

computation to run first

-> Sem r b

computation to run afterward (even if an exception was raised)

-> Sem r a 

Like bracket, but for the simple case of one computation to run afterward.

Since: 0.4.0.0

onException Source #

Arguments

:: Member Resource r 
=> Sem r a

computation to run first

-> Sem r b

computation to run afterward if an exception was raised

-> Sem r a 

Like bracketOnError, but for the simple case of one computation to run afterward.

Since: 0.4.0.0

Interpretations

runResource :: forall r a. Sem (Resource ': r) a -> Sem r a Source #

Run a Resource effect purely.

Since: 0.4.0.0

runResourceInIO Source #

Arguments

:: Member (Lift IO) r 
=> (forall x. Sem r x -> IO x)

Strategy for lowering a Sem action down to IO. This is likely some combination of runM and other interpreters composed via .@.

-> Sem (Resource ': r) a 
-> Sem r a 

Run a Resource effect via in terms of bracket.

Note: This function used to be called runResource prior to 0.4.0.0.

Since: 0.4.0.0

runResourceBase :: forall r a. LastMember (Lift IO) r => Sem (Resource ': r) a -> Sem r a Source #

A more flexible --- though less safe --- version of runResourceInIO.

This function is capable of running Resource effects anywhere within an effect stack, without relying on an explicit function to lower it into IO. Notably, this means that State effects will be consistent in the presence of Resource.

runResourceBase is safe whenever you're concerned about exceptions thrown by effects _already handled_ in your effect stack, or in IO code run directly inside of bracket. It is not safe against exceptions thrown explicitly at the main thread. If this is not safe enough for your use-case, use runResourceInIO instead.

This function creates a thread, and so should be compiled with -threaded.

Since: 0.5.0.0