monad-finally-0.1.2.1: Guard monadic computations with cleanup actions
Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.Monad.Finally

Description

Guarding monadic computations with cleanup actions.

Synopsis

Documentation

class (Applicative μ, Monad μ) => MonadFinally μ where Source #

Class of monads that support guarding computations with cleanup actions.

Minimal complete definition

finally' | bracket'

Methods

finally' :: μ α -> (Maybe α -> μ β) -> μ (α, β) Source #

finally' m f runs computation m and then

  1. runs f (Just x) if m produced a result x. The result of that is returned alongside with x.
  2. runs f Nothing otherwise.

finally :: μ α -> μ β -> μ α Source #

A simplified version of finally' in which the cleanup action does not care about the result of the main computation. The default implementation is

    finally m = fmap fst . finally' m . const

bracket' Source #

Arguments

:: μ r

Acquire resource

-> (r -> Maybe α -> μ β)

Release resource

-> (r -> μ α)

Main computation

-> μ (α, β) 

Safely acquire a resource and use it in a computation, releasing it even when the computation does not produce a result.

bracket :: μ r -> (r -> μ β) -> (r -> μ α) -> μ α Source #

A simplified version of bracket' in which the releasing action does not care about the result of the main computation. The default implementation is

    bracket acquire release =
      fmap fst . bracket' acquire (const . release)

Instances

Instances details
MonadFinally Identity Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: Identity α -> (Maybe α -> Identity β) -> Identity (α, β) Source #

finally :: Identity α -> Identity β -> Identity α Source #

bracket' :: Identity r -> (r -> Maybe α -> Identity β) -> (r -> Identity α) -> Identity (α, β) Source #

bracket :: Identity r -> (r -> Identity β) -> (r -> Identity α) -> Identity α Source #

MonadFinally IO Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: IO α -> (Maybe α -> IO β) -> IO (α, β) Source #

finally :: IO α -> IO β -> IO α Source #

bracket' :: IO r -> (r -> Maybe α -> IO β) -> (r -> IO α) -> IO (α, β) Source #

bracket :: IO r -> (r -> IO β) -> (r -> IO α) -> IO α Source #

MonadFinally μ => MonadFinally (MaybeT μ) Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: MaybeT μ α -> (Maybe α -> MaybeT μ β) -> MaybeT μ (α, β) Source #

finally :: MaybeT μ α -> MaybeT μ β -> MaybeT μ α Source #

bracket' :: MaybeT μ r -> (r -> Maybe α -> MaybeT μ β) -> (r -> MaybeT μ α) -> MaybeT μ (α, β) Source #

bracket :: MaybeT μ r -> (r -> MaybeT μ β) -> (r -> MaybeT μ α) -> MaybeT μ α Source #

(MonadFinally μ, Monoid w) => MonadFinally (AccumT w μ) Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: AccumT w μ α -> (Maybe α -> AccumT w μ β) -> AccumT w μ (α, β) Source #

finally :: AccumT w μ α -> AccumT w μ β -> AccumT w μ α Source #

bracket' :: AccumT w μ r -> (r -> Maybe α -> AccumT w μ β) -> (r -> AccumT w μ α) -> AccumT w μ (α, β) Source #

bracket :: AccumT w μ r -> (r -> AccumT w μ β) -> (r -> AccumT w μ α) -> AccumT w μ α Source #

(MonadFinally μ, Error e) => MonadFinally (ErrorT e μ) Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: ErrorT e μ α -> (Maybe α -> ErrorT e μ β) -> ErrorT e μ (α, β) Source #

finally :: ErrorT e μ α -> ErrorT e μ β -> ErrorT e μ α Source #

bracket' :: ErrorT e μ r -> (r -> Maybe α -> ErrorT e μ β) -> (r -> ErrorT e μ α) -> ErrorT e μ (α, β) Source #

bracket :: ErrorT e μ r -> (r -> ErrorT e μ β) -> (r -> ErrorT e μ α) -> ErrorT e μ α Source #

MonadFinally μ => MonadFinally (ExceptT e μ) Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: ExceptT e μ α -> (Maybe α -> ExceptT e μ β) -> ExceptT e μ (α, β) Source #

finally :: ExceptT e μ α -> ExceptT e μ β -> ExceptT e μ α Source #

bracket' :: ExceptT e μ r -> (r -> Maybe α -> ExceptT e μ β) -> (r -> ExceptT e μ α) -> ExceptT e μ (α, β) Source #

bracket :: ExceptT e μ r -> (r -> ExceptT e μ β) -> (r -> ExceptT e μ α) -> ExceptT e μ α Source #

MonadFinally μ => MonadFinally (ReaderT r μ) Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: ReaderT r μ α -> (Maybe α -> ReaderT r μ β) -> ReaderT r μ (α, β) Source #

finally :: ReaderT r μ α -> ReaderT r μ β -> ReaderT r μ α Source #

bracket' :: ReaderT r μ r0 -> (r0 -> Maybe α -> ReaderT r μ β) -> (r0 -> ReaderT r μ α) -> ReaderT r μ (α, β) Source #

bracket :: ReaderT r μ r0 -> (r0 -> ReaderT r μ β) -> (r0 -> ReaderT r μ α) -> ReaderT r μ α Source #

MonadFinally μ => MonadFinally (StateT s μ) Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: StateT s μ α -> (Maybe α -> StateT s μ β) -> StateT s μ (α, β) Source #

finally :: StateT s μ α -> StateT s μ β -> StateT s μ α Source #

bracket' :: StateT s μ r -> (r -> Maybe α -> StateT s μ β) -> (r -> StateT s μ α) -> StateT s μ (α, β) Source #

bracket :: StateT s μ r -> (r -> StateT s μ β) -> (r -> StateT s μ α) -> StateT s μ α Source #

MonadFinally μ => MonadFinally (StateT s μ) Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: StateT s μ α -> (Maybe α -> StateT s μ β) -> StateT s μ (α, β) Source #

finally :: StateT s μ α -> StateT s μ β -> StateT s μ α Source #

bracket' :: StateT s μ r -> (r -> Maybe α -> StateT s μ β) -> (r -> StateT s μ α) -> StateT s μ (α, β) Source #

bracket :: StateT s μ r -> (r -> StateT s μ β) -> (r -> StateT s μ α) -> StateT s μ α Source #

(MonadFinally μ, Monoid w) => MonadFinally (WriterT w μ) Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: WriterT w μ α -> (Maybe α -> WriterT w μ β) -> WriterT w μ (α, β) Source #

finally :: WriterT w μ α -> WriterT w μ β -> WriterT w μ α Source #

bracket' :: WriterT w μ r -> (r -> Maybe α -> WriterT w μ β) -> (r -> WriterT w μ α) -> WriterT w μ (α, β) Source #

bracket :: WriterT w μ r -> (r -> WriterT w μ β) -> (r -> WriterT w μ α) -> WriterT w μ α Source #

(MonadFinally μ, Monoid w) => MonadFinally (WriterT w μ) Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: WriterT w μ α -> (Maybe α -> WriterT w μ β) -> WriterT w μ (α, β) Source #

finally :: WriterT w μ α -> WriterT w μ β -> WriterT w μ α Source #

bracket' :: WriterT w μ r -> (r -> Maybe α -> WriterT w μ β) -> (r -> WriterT w μ α) -> WriterT w μ (α, β) Source #

bracket :: WriterT w μ r -> (r -> WriterT w μ β) -> (r -> WriterT w μ α) -> WriterT w μ α Source #

MonadFinally μ => MonadFinally (AbortT e μ) Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: AbortT e μ α -> (Maybe α -> AbortT e μ β) -> AbortT e μ (α, β) Source #

finally :: AbortT e μ α -> AbortT e μ β -> AbortT e μ α Source #

bracket' :: AbortT e μ r -> (r -> Maybe α -> AbortT e μ β) -> (r -> AbortT e μ α) -> AbortT e μ (α, β) Source #

bracket :: AbortT e μ r -> (r -> AbortT e μ β) -> (r -> AbortT e μ α) -> AbortT e μ α Source #

MonadFinally μ => MonadFinally (FinishT β μ) Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: FinishT β μ α -> (Maybe α -> FinishT β μ β0) -> FinishT β μ (α, β0) Source #

finally :: FinishT β μ α -> FinishT β μ β0 -> FinishT β μ α Source #

bracket' :: FinishT β μ r -> (r -> Maybe α -> FinishT β μ β0) -> (r -> FinishT β μ α) -> FinishT β μ (α, β0) Source #

bracket :: FinishT β μ r -> (r -> FinishT β μ β0) -> (r -> FinishT β μ α) -> FinishT β μ α Source #

(MonadFinally μ, Monoid w) => MonadFinally (RWST r w s μ) Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: RWST r w s μ α -> (Maybe α -> RWST r w s μ β) -> RWST r w s μ (α, β) Source #

finally :: RWST r w s μ α -> RWST r w s μ β -> RWST r w s μ α Source #

bracket' :: RWST r w s μ r0 -> (r0 -> Maybe α -> RWST r w s μ β) -> (r0 -> RWST r w s μ α) -> RWST r w s μ (α, β) Source #

bracket :: RWST r w s μ r0 -> (r0 -> RWST r w s μ β) -> (r0 -> RWST r w s μ α) -> RWST r w s μ α Source #

(MonadFinally μ, Monoid w) => MonadFinally (RWST r w s μ) Source # 
Instance details

Defined in Control.Monad.Finally

Methods

finally' :: RWST r w s μ α -> (Maybe α -> RWST r w s μ β) -> RWST r w s μ (α, β) Source #

finally :: RWST r w s μ α -> RWST r w s μ β -> RWST r w s μ α Source #

bracket' :: RWST r w s μ r0 -> (r0 -> Maybe α -> RWST r w s μ β) -> (r0 -> RWST r w s μ α) -> RWST r w s μ (α, β) Source #

bracket :: RWST r w s μ r0 -> (r0 -> RWST r w s μ β) -> (r0 -> RWST r w s μ α) -> RWST r w s μ α Source #

chainCleanups :: MonadFinally μ => [μ α] -> μ () Source #

Run the provided list of cleanup actions sequentually, attempting to run the next action even if the previous one did not produce a result.

finallyMany :: MonadFinally μ => μ α -> [μ β] -> μ α Source #

A variant of finally that combines multiple cleanup actions with chainCleanups.

onEscape :: MonadFinally μ => μ α -> μ β -> μ α Source #

onEscape m c runs computation m and then, if it did not produce a result, runs computation c.

onEscapeMany :: MonadFinally μ => μ α -> [μ β] -> μ α Source #

A variant of onEscape that combines multiple cleanup actions with chainCleanups.

bracket_ Source #

Arguments

:: MonadFinally μ 
=> μ r

Acquire resource

-> μ β

Release resource

-> μ α

Main computation

-> μ α 

A variant of bracket where acquired value is not needed (e.g. using a static resource).

bracketOnEscape Source #

Arguments

:: MonadFinally μ 
=> μ r

Acquire resource

-> (r -> μ β)

Release resource

-> (r -> μ α)

Main computation

-> μ α 

A variant of bracket that releases the acquired resource only when the main computation does not produce a value.