planet-mitchell-0.1.0: Planet Mitchell

Safe HaskellSafe
LanguageHaskell2010

Managed

Contents

Synopsis

Managed

data Managed a #

A managed resource that you acquire using with

Instances
Monad Managed 
Instance details

Defined in Control.Monad.Managed

Methods

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

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

return :: a -> Managed a #

fail :: String -> Managed a #

Functor Managed 
Instance details

Defined in Control.Monad.Managed

Methods

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

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

Applicative Managed 
Instance details

Defined in Control.Monad.Managed

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 
Instance details

Defined in Control.Monad.Managed

Methods

liftIO :: IO a -> Managed a #

MonadManaged Managed 
Instance details

Defined in Control.Monad.Managed

Methods

using :: Managed a -> Managed a #

Floating a => Floating (Managed a) 
Instance details

Defined in Control.Monad.Managed

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) 
Instance details

Defined in Control.Monad.Managed

Methods

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

recip :: Managed a -> Managed a #

fromRational :: Rational -> Managed a #

Num a => Num (Managed a) 
Instance details

Defined in Control.Monad.Managed

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) 
Instance details

Defined in Control.Monad.Managed

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) 
Instance details

Defined in Control.Monad.Managed

Methods

mempty :: Managed a #

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

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

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

Build a Managed value

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

Like managed but for resource-less operations.

with :: Managed a -> (a -> IO r) -> IO r #

Acquire a Managed value

This is a potentially unsafe function since it allows a resource to escape its scope. For example, you might use Managed to safely acquire a file handle, like this:

import qualified System.IO as IO

example :: Managed Handle
example = managed (IO.withFile "foo.txt" IO.ReadMode)

... and if you never used the with function then you would never run the risk of accessing the Handle after the file was closed. However, if you use with then you can incorrectly access the handle after the handle is closed, like this:

bad :: IO ()
bad = do
    handle <- with example return
    IO.hPutStrLn handle "bar"  -- This will fail because the handle is closed

... so only use with if you know what you are doing and you're returning a value that is not a resource being managed.

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

Run a Managed computation, enforcing that no acquired resources leak

MonadManaged

class MonadIO m => MonadManaged (m :: * -> *) where #

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 #

Instances
MonadManaged Managed 
Instance details

Defined in Control.Monad.Managed

Methods

using :: Managed a -> Managed a #

MonadManaged m => MonadManaged (MaybeT m) 
Instance details

Defined in Control.Monad.Managed

Methods

using :: Managed a -> MaybeT m a #

MonadManaged m => MonadManaged (IdentityT m) 
Instance details

Defined in Control.Monad.Managed

Methods

using :: Managed a -> IdentityT m a #

MonadManaged m => MonadManaged (ExceptT e m) 
Instance details

Defined in Control.Monad.Managed

Methods

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

(Monoid w, MonadManaged m) => MonadManaged (WriterT w m) 
Instance details

Defined in Control.Monad.Managed

Methods

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

MonadManaged m => MonadManaged (StateT s m) 
Instance details

Defined in Control.Monad.Managed

Methods

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

MonadManaged m => MonadManaged (StateT s m) 
Instance details

Defined in Control.Monad.Managed

Methods

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

(Monoid w, MonadManaged m) => MonadManaged (WriterT w m) 
Instance details

Defined in Control.Monad.Managed

Methods

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

MonadManaged m => MonadManaged (ReaderT r m) 
Instance details

Defined in Control.Monad.Managed

Methods

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

MonadManaged m => MonadManaged (ContT r m) 
Instance details

Defined in Control.Monad.Managed

Methods

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

(Monoid w, MonadManaged m) => MonadManaged (RWST r w s m) 
Instance details

Defined in Control.Monad.Managed

Methods

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

(Monoid w, MonadManaged m) => MonadManaged (RWST r w s m) 
Instance details

Defined in Control.Monad.Managed

Methods

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