general-allocate-0.2.3.1: Exception-safe resource management in more monads
CopyrightCopyright 2022 Shea Levy.
LicenseApache-2.0
Maintainershea@shealevy.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.GeneralAllocate

Description

This module provides a general interface for describing the allocation and release of some resource in some monadic context.

For using the resources safely, see Control.Monad.With and Control.Monad.Allocate.

This design and implementation is heavily based on Acquire from resourcet, including some code copied verbatim and then generalized appropriately. resourcet is Copyright (c)2011, Michael Snoyman, and licensed under the BSD 3-clause license available at LICENSE.resourcet.

Synopsis

Documentation

newtype GeneralAllocate m e releaseReturn releaseArg a Source #

Describe the allocation and release of an a in m.

In monads which allow this, the allocation action is run with exceptions masked. The argument to the action allows the allocation to run some action with the masking state restored to its prior state. In monads without masking, the argument is id.

m
The monad to allocate in
e
A data type for a failure condition, typically SomeException
releaseReturn
State to be returned upon resource release. Mainly useful for proper threading of monadic state in error conditions.
releaseArg
An argument to be passed to the release action upon successful completion of usage.
a
The type of the resource

Constructors

GeneralAllocate ((forall x. m x -> m x) -> m (GeneralAllocated m e releaseReturn releaseArg a)) 

Instances

Instances details
(MonadWith m, Monoid releaseReturn, e ~ WithException m) => Applicative (GeneralAllocate m e releaseReturn releaseArg) Source # 
Instance details

Defined in Data.GeneralAllocate

Methods

pure :: a -> GeneralAllocate m e releaseReturn releaseArg a #

(<*>) :: GeneralAllocate m e releaseReturn releaseArg (a -> b) -> GeneralAllocate m e releaseReturn releaseArg a -> GeneralAllocate m e releaseReturn releaseArg b #

liftA2 :: (a -> b -> c) -> GeneralAllocate m e releaseReturn releaseArg a -> GeneralAllocate m e releaseReturn releaseArg b -> GeneralAllocate m e releaseReturn releaseArg c #

(*>) :: GeneralAllocate m e releaseReturn releaseArg a -> GeneralAllocate m e releaseReturn releaseArg b -> GeneralAllocate m e releaseReturn releaseArg b #

(<*) :: GeneralAllocate m e releaseReturn releaseArg a -> GeneralAllocate m e releaseReturn releaseArg b -> GeneralAllocate m e releaseReturn releaseArg a #

Functor m => Functor (GeneralAllocate m e releaseReturn releaseArg) Source # 
Instance details

Defined in Data.GeneralAllocate

Methods

fmap :: (a -> b) -> GeneralAllocate m e releaseReturn releaseArg a -> GeneralAllocate m e releaseReturn releaseArg b #

(<$) :: a -> GeneralAllocate m e releaseReturn releaseArg b -> GeneralAllocate m e releaseReturn releaseArg a #

(MonadWith m, Monoid releaseReturn, e ~ WithException m) => Monad (GeneralAllocate m e releaseReturn releaseArg) Source # 
Instance details

Defined in Data.GeneralAllocate

Methods

(>>=) :: GeneralAllocate m e releaseReturn releaseArg a -> (a -> GeneralAllocate m e releaseReturn releaseArg b) -> GeneralAllocate m e releaseReturn releaseArg b #

(>>) :: GeneralAllocate m e releaseReturn releaseArg a -> GeneralAllocate m e releaseReturn releaseArg b -> GeneralAllocate m e releaseReturn releaseArg b #

return :: a -> GeneralAllocate m e releaseReturn releaseArg a #

data GeneralAllocated m e releaseReturn releaseArg a Source #

A resource allocated and releasable in m.

m
The monad to allocate in
e
A data type for a failure condition, typically SomeException
releaseReturn
State to be returned upon resource release. Mainly useful for proper threading of monadic state in error conditions.
releaseArg
An argument to be passed to the release action upon successful completion of usage.
a
The type of the resource

Constructors

GeneralAllocated 

Fields

Instances

Instances details
Functor (GeneralAllocated m e releaseReturn releaseArg) Source # 
Instance details

Defined in Data.GeneralAllocate

Methods

fmap :: (a -> b) -> GeneralAllocated m e releaseReturn releaseArg a -> GeneralAllocated m e releaseReturn releaseArg b #

(<$) :: a -> GeneralAllocated m e releaseReturn releaseArg b -> GeneralAllocated m e releaseReturn releaseArg a #

data GeneralReleaseType e a Source #

Types of release requests that can occur.

e
A data type for a failure condition, typically SomeException
a
A data type for success conditions

Constructors

ReleaseSuccess !a

The resource was used successfully

ReleaseFailure !e

Some kind of error occured while the resource was held.

The error need not have originated from using the resource itself.

Instances

Instances details
Functor (GeneralReleaseType e) Source # 
Instance details

Defined in Data.GeneralAllocate

Methods

fmap :: (a -> b) -> GeneralReleaseType e a -> GeneralReleaseType e b #

(<$) :: a -> GeneralReleaseType e b -> GeneralReleaseType e a #