Copyright | Copyright 2022 Shea Levy. |
---|---|
License | Apache-2.0 |
Maintainer | shea@shealevy.com |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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
- newtype GeneralAllocate m e releaseReturn releaseArg a = GeneralAllocate ((forall x. m x -> m x) -> m (GeneralAllocated m e releaseReturn releaseArg a))
- data GeneralAllocated m e releaseReturn releaseArg a = GeneralAllocated {
- allocatedResource :: !a
- releaseAllocated :: !(GeneralReleaseType e releaseArg -> m releaseReturn)
- data GeneralReleaseType e a
- = ReleaseSuccess !a
- | ReleaseFailure !e
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
GeneralAllocate ((forall x. m x -> m x) -> m (GeneralAllocated m e releaseReturn releaseArg a)) |
Instances
(MonadWith m, Monoid releaseReturn, e ~ WithException m) => Applicative (GeneralAllocate m e releaseReturn releaseArg) Source # | |
Defined in Data.GeneralAllocate 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 # | |
Defined in Data.GeneralAllocate 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 # | |
Defined in Data.GeneralAllocate (>>=) :: 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
GeneralAllocated | |
|
Instances
Functor (GeneralAllocated m e releaseReturn releaseArg) Source # | |
Defined in Data.GeneralAllocate 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
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
Functor (GeneralReleaseType e) Source # | |
Defined in Data.GeneralAllocate fmap :: (a -> b) -> GeneralReleaseType e a -> GeneralReleaseType e b # (<$) :: a -> GeneralReleaseType e b -> GeneralReleaseType e a # |