effet-0.3.0.1: An Effect System based on Type Classes

Copyright(c) Michael Szvetits 2020
LicenseBSD3 (see the file LICENSE)
Maintainertypedbyte@qualified.name
Stabilitystable
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Control.Effect.Managed

Contents

Description

The managed effect allows a computation to allocate resources which are guaranteed to be released after the end of the computation. This effect provides a monadic interface for managing one or more long-living resources in a more readable way than nesting bracket-style operations of the Control.Effect.Resource effect.

Synopsis

Tagged Managed Effect

class Monad m => Managed' tag m where Source #

An effect that allows a computation to allocate resources which are guaranteed to be released after the computation.

Since: 0.3.0.0

Methods

manage' Source #

Arguments

:: m a

The computation which acquires the resource.

-> (a -> m b)

The computation which releases the resource.

-> m a

The acquired resource.

Acquire a resource by specifying an acquisition action and a release action to be used for cleanup after the computation.

Since: 0.3.0.0

Instances
MonadBase IO m => Managed' (tag :: k) (Bracket m m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

manage' :: Bracket m m a -> (a -> Bracket m m b) -> Bracket m m a Source #

Handle (Managed' tag) t m => Managed' (tag :: k) (EachVia (Managed' tag ': effs) t m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

manage' :: EachVia (Managed' tag ': effs) t m a -> (a -> EachVia (Managed' tag ': effs) t m b) -> EachVia (Managed' tag ': effs) t m a Source #

Find (Managed' tag) effs t m => Managed' (tag :: k) (EachVia (other ': effs) t m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

manage' :: EachVia (other ': effs) t m a -> (a -> EachVia (other ': effs) t m b) -> EachVia (other ': effs) t m a Source #

Control (Managed' tag) t m => Managed' (tag :: k) (EachVia ([] :: [Effect]) t m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

manage' :: EachVia [] t m a -> (a -> EachVia [] t m b) -> EachVia [] t m a Source #

Managed' new m => Managed' (tag :: k2) (Tagger tag new m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

manage' :: Tagger tag new m a -> (a -> Tagger tag new m b) -> Tagger tag new m a Source #

Untagged Managed Effect

If you don't require disambiguation of multiple managed effects (i.e., you only have one managed effect in your monadic context), it is recommended to always use the untagged managed effect.

manage :: Managed m => m a -> (a -> m b) -> m a Source #

Interpretations

data Bracket n m a Source #

The bracket-based interpreter of the managed effect. This type implements the Managed' type class by using bracket, thus requiring IO at the bottom of the monad transformer stack.

When interpreting the effect, you usually don't interact with this type directly, but instead use one of its corresponding interpretation functions.

Since: 0.3.0.0

Instances
MonadBase IO m => Managed' (tag :: k) (Bracket m m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

manage' :: Bracket m m a -> (a -> Bracket m m b) -> Bracket m m a Source #

MonadBase b m => MonadBase b (Bracket n m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

liftBase :: b α -> Bracket n m α #

MonadBaseControl b m => MonadBaseControl b (Bracket n m) Source # 
Instance details

Defined in Control.Effect.Managed

Associated Types

type StM (Bracket n m) a :: Type #

Methods

liftBaseWith :: (RunInBase (Bracket n m) b -> b a) -> Bracket n m a #

restoreM :: StM (Bracket n m) a -> Bracket n m a #

MonadTrans (Bracket n) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

lift :: Monad m => m a -> Bracket n m a #

MonadTransControl (Bracket n) Source # 
Instance details

Defined in Control.Effect.Managed

Associated Types

type StT (Bracket n) a :: Type #

Methods

liftWith :: Monad m => (Run (Bracket n) -> m a) -> Bracket n m a #

restoreT :: Monad m => m (StT (Bracket n) a) -> Bracket n m a #

Monad m => Monad (Bracket n m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

(>>=) :: Bracket n m a -> (a -> Bracket n m b) -> Bracket n m b #

(>>) :: Bracket n m a -> Bracket n m b -> Bracket n m b #

return :: a -> Bracket n m a #

fail :: String -> Bracket n m a #

Functor m => Functor (Bracket n m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

fmap :: (a -> b) -> Bracket n m a -> Bracket n m b #

(<$) :: a -> Bracket n m b -> Bracket n m a #

Applicative m => Applicative (Bracket n m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

pure :: a -> Bracket n m a #

(<*>) :: Bracket n m (a -> b) -> Bracket n m a -> Bracket n m b #

liftA2 :: (a -> b -> c) -> Bracket n m a -> Bracket n m b -> Bracket n m c #

(*>) :: Bracket n m a -> Bracket n m b -> Bracket n m b #

(<*) :: Bracket n m a -> Bracket n m b -> Bracket n m a #

MonadIO m => MonadIO (Bracket n m) Source # 
Instance details

Defined in Control.Effect.Managed

Methods

liftIO :: IO a -> Bracket n m a #

type StT (Bracket n) a Source # 
Instance details

Defined in Control.Effect.Managed

type StT (Bracket n) a = StT (ReaderT (IORef [n ()])) a
type StM (Bracket n m) a Source # 
Instance details

Defined in Control.Effect.Managed

type StM (Bracket n m) a = StM (ReaderT (IORef [n ()]) m) a

runManaged' :: forall tag m a. MonadBaseControl IO m => (Managed' tag `Via` Bracket m) m a -> m a Source #

Runs the managed effect using bracket.

Since: 0.3.0.0

runManaged :: MonadBaseControl IO m => (Managed `Via` Bracket m) m a -> m a Source #

The untagged version of runManaged'.

Since: 0.3.0.0

Tagging and Untagging

Conversion functions between the tagged and untagged managed effect, usually used in combination with type applications, like:

    tagManaged' @"newTag" program
    retagManaged' @"oldTag" @"newTag" program
    untagManaged' @"erasedTag" program

tagManaged' :: forall new m a. Via (Managed' G) (Tagger G new) m a -> m a Source #

retagManaged' :: forall tag new m a. Via (Managed' tag) (Tagger tag new) m a -> m a Source #

untagManaged' :: forall tag m a. Via (Managed' tag) (Tagger tag G) m a -> m a Source #