Safe Haskell | None |
---|---|

Language | Haskell98 |

Guarding monadic computations with cleanup actions.

- class (Applicative μ, Monad μ) => MonadFinally μ where
- chainCleanups :: MonadFinally μ => [μ α] -> μ ()
- finallyMany :: MonadFinally μ => μ α -> [μ β] -> μ α
- onEscape :: MonadFinally μ => μ α -> μ β -> μ α
- onEscapeMany :: MonadFinally μ => μ α -> [μ β] -> μ α
- bracket_ :: MonadFinally μ => μ r -> μ β -> μ α -> μ α
- bracketOnEscape :: MonadFinally μ => μ r -> (r -> μ β) -> (r -> μ α) -> μ α

# Documentation

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

Class of monads that support guarding computations with cleanup actions.

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

runs computation `finally'`

m f`m`

and then

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`

:: μ 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.

MonadFinally IO Source # | |

MonadFinally Identity Source # | |

MonadFinally μ => MonadFinally (MaybeT μ) Source # | |

MonadFinally μ => MonadFinally (ExceptT e μ) Source # | |

MonadFinally μ => MonadFinally (AbortT e μ) Source # | |

MonadFinally μ => MonadFinally (FinishT β μ) Source # | |

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

MonadFinally μ => MonadFinally (StateT s μ) Source # | |

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

MonadFinally μ => MonadFinally (StateT s μ) Source # | |

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

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

MonadFinally μ => MonadFinally (ReaderT * r μ) Source # | |

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

(MonadFinally μ, Monoid w) => MonadFinally (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 #

runs computation `onEscape`

m c`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`

.

:: MonadFinally μ | |

=> μ r | Acquire resource |

-> μ β | Release resource |

-> μ α | Main computation |

-> μ α |

A variant of `bracket`

where acquired value is not needed (e.g. using
a static resource).

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