managed-1.0.6: A monad for managed values

Safe HaskellSafe
LanguageHaskell98

Control.Monad.Managed.Safe

Contents

Description

This module is a safer subset of Control.Monad.Managed that only lets you unwrap the Managed type using runManaged. This enforces that you never leak acquired resources from a Managed computation.

In general, you should strive to propagate the Managed type as much as possible and use runManaged when you are done with acquired resources. However, there are legitimate circumstances where you want to return a value other than acquired resource from the bracketed computation, which requires using with.

This module is not the default because you can also use the Managed type for callback-based code that is completely unrelated to resources.

Synopsis

Managed

data Managed a Source #

A managed resource that you acquire using with

Instances

Monad Managed Source # 

Methods

(>>=) :: Managed a -> (a -> Managed b) -> Managed b #

(>>) :: Managed a -> Managed b -> Managed b #

return :: a -> Managed a #

fail :: String -> Managed a #

Functor Managed Source # 

Methods

fmap :: (a -> b) -> Managed a -> Managed b #

(<$) :: a -> Managed b -> Managed a #

Applicative Managed Source # 

Methods

pure :: a -> Managed a #

(<*>) :: Managed (a -> b) -> Managed a -> Managed b #

liftA2 :: (a -> b -> c) -> Managed a -> Managed b -> Managed c #

(*>) :: Managed a -> Managed b -> Managed b #

(<*) :: Managed a -> Managed b -> Managed a #

MonadIO Managed Source # 

Methods

liftIO :: IO a -> Managed a #

MonadManaged Managed Source # 

Methods

using :: Managed a -> Managed a Source #

Floating a => Floating (Managed a) Source # 

Methods

pi :: Managed a #

exp :: Managed a -> Managed a #

log :: Managed a -> Managed a #

sqrt :: Managed a -> Managed a #

(**) :: Managed a -> Managed a -> Managed a #

logBase :: Managed a -> Managed a -> Managed a #

sin :: Managed a -> Managed a #

cos :: Managed a -> Managed a #

tan :: Managed a -> Managed a #

asin :: Managed a -> Managed a #

acos :: Managed a -> Managed a #

atan :: Managed a -> Managed a #

sinh :: Managed a -> Managed a #

cosh :: Managed a -> Managed a #

tanh :: Managed a -> Managed a #

asinh :: Managed a -> Managed a #

acosh :: Managed a -> Managed a #

atanh :: Managed a -> Managed a #

log1p :: Managed a -> Managed a #

expm1 :: Managed a -> Managed a #

log1pexp :: Managed a -> Managed a #

log1mexp :: Managed a -> Managed a #

Fractional a => Fractional (Managed a) Source # 

Methods

(/) :: Managed a -> Managed a -> Managed a #

recip :: Managed a -> Managed a #

fromRational :: Rational -> Managed a #

Num a => Num (Managed a) Source # 

Methods

(+) :: Managed a -> Managed a -> Managed a #

(-) :: Managed a -> Managed a -> Managed a #

(*) :: Managed a -> Managed a -> Managed a #

negate :: Managed a -> Managed a #

abs :: Managed a -> Managed a #

signum :: Managed a -> Managed a #

fromInteger :: Integer -> Managed a #

Semigroup a => Semigroup (Managed a) Source # 

Methods

(<>) :: Managed a -> Managed a -> Managed a #

sconcat :: NonEmpty (Managed a) -> Managed a #

stimes :: Integral b => b -> Managed a -> Managed a #

Monoid a => Monoid (Managed a) Source # 

Methods

mempty :: Managed a #

mappend :: Managed a -> Managed a -> Managed a #

mconcat :: [Managed a] -> Managed a #

class MonadIO m => MonadManaged m where Source #

You can embed a Managed action within any Monad that implements MonadManaged by using the using function

All instances must obey the following two laws:

using (return x) = return x

using (m >>= f) = using m >>= \x -> using (f x)

Minimal complete definition

using

Methods

using :: Managed a -> m a Source #

Instances

MonadManaged Managed Source # 

Methods

using :: Managed a -> Managed a Source #

MonadManaged m => MonadManaged (MaybeT m) Source # 

Methods

using :: Managed a -> MaybeT m a Source #

(Monoid w, MonadManaged m) => MonadManaged (WriterT w m) Source # 

Methods

using :: Managed a -> WriterT w m a Source #

(Monoid w, MonadManaged m) => MonadManaged (WriterT w m) Source # 

Methods

using :: Managed a -> WriterT w m a Source #

MonadManaged m => MonadManaged (StateT s m) Source # 

Methods

using :: Managed a -> StateT s m a Source #

MonadManaged m => MonadManaged (StateT s m) Source # 

Methods

using :: Managed a -> StateT s m a Source #

MonadManaged m => MonadManaged (IdentityT * m) Source # 

Methods

using :: Managed a -> IdentityT * m a Source #

MonadManaged m => MonadManaged (ExceptT e m) Source # 

Methods

using :: Managed a -> ExceptT e m a Source #

MonadManaged m => MonadManaged (ReaderT * r m) Source # 

Methods

using :: Managed a -> ReaderT * r m a Source #

MonadManaged m => MonadManaged (ContT * r m) Source # 

Methods

using :: Managed a -> ContT * r m a Source #

(Monoid w, MonadManaged m) => MonadManaged (RWST r w s m) Source # 

Methods

using :: Managed a -> RWST r w s m a Source #

(Monoid w, MonadManaged m) => MonadManaged (RWST r w s m) Source # 

Methods

using :: Managed a -> RWST r w s m a Source #

managed :: (forall r. (a -> IO r) -> IO r) -> Managed a Source #

Build a Managed value

managed_ :: (forall r. IO r -> IO r) -> Managed () Source #

Like managed but for resource-less operations.

runManaged :: Managed () -> IO () Source #

Run a Managed computation, enforcing that no acquired resources leak

Re-exports