Description

Guarding monadic computations with cleanup actions.

Synopsis

Documentation

Class of monads that support guarding computations with cleanup actions.

Minimal complete definition

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


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

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.

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).

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.