polysemy-1.8.0.0: Higher-order, low-boilerplate free monads.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Polysemy.Resource

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 

Actions

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

bracket_ Source #

Arguments

:: Member Resource r 
=> Sem r a

computation to run first

-> Sem r b

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

-> Sem r c

computation to run in-between

-> Sem r c 

A variant of bracket where the return value from the first computation is not required.

cf. bracket and bracket_

Since: 1.5.0.0

bracketOnError :: forall r a c b. Member Resource r => Sem r a -> (a -> Sem r c) -> (a -> Sem r b) -> Sem r b 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: 1.0.0.0

resourceToIOFinal :: Member (Final IO) r => Sem (Resource ': r) a -> Sem r a Source #

Run a Resource effect in terms of bracket through final IO

Beware: Effects that aren't interpreted in terms of IO will have local state semantics in regards to Resource effects interpreted this way. See Final.

Since: 1.2.0.0