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

Control.Monad.NoContinuation.Resource

Description

This module defines a MonadTransformer, NoContinuationResourceT, which allows for running MonadAllocate code in pure PrimMonads. This allows for writing monad-generic resource-safe code and freely switching between tResourceT on top of IO and the pure NoContinuationResourceT on top of ST.

Synopsis

Documentation

data NoContinuationResourceT m a Source #

A MonadTransformer turning any PrimMonad that is a MonadWith into a MonadAllocate

Note that the MonadAllocate instance is only valid if the underlying monad satisfies the "no continuation" condition, i.e. that if execution of a computation exits a given lexical scope we are guaranteed that either all of the actions within that scope have executed or the entire monadic computation has been terminated.

The most common factors violating "no continuation" are call/cc and exception catching. A monad which allows exception throwing but not catching is not thereby disqualified, as any thrown exception will of necessity propagate until it terminates the entire monadic computation.

In conjunction with the PrimMonad requirement, this essentially means the base of m must be an ST and there must be no ContT in the stack.

Instances

Instances details
MonadTrans NoContinuationResourceT Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

Methods

lift :: Monad m => m a -> NoContinuationResourceT m a #

MonadReader r m => MonadReader r (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

MonadState s m => MonadState s (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

Methods

get :: NoContinuationResourceT m s #

put :: s -> NoContinuationResourceT m () #

state :: (s -> (a, s)) -> NoContinuationResourceT m a #

MonadWriter w m => MonadWriter w (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

MonadFail m => MonadFail (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

MonadFix m => MonadFix (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

Alternative m => Alternative (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

Applicative m => Applicative (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

Functor m => Functor (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

Monad m => Monad (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

MonadPlus m => MonadPlus (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

(PrimMonad m, MonadWith m) => MonadAllocate (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

PrimMonad m => PrimMonad (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

Associated Types

type PrimState (NoContinuationResourceT m) #

type AllocationContext (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

type AllocationException (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

type GeneralReleaseKey (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

type PrimState (NoContinuationResourceT m) Source # 
Instance details

Defined in Control.Monad.NoContinuation.Resource.Internal

runNoContinuationResourceT :: (PrimMonad m, MonadWith m) => NoContinuationResourceT m a -> m a Source #

Run a NoContinuationResourceT computation, freeing all resources before continuing.