managed-1.0.8: A monad for managed values

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

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)

Methods

using :: Managed a -> m a Source #

Instances

managed :: MonadManaged m => (forall r. (a -> IO r) -> IO r) -> m a Source #

Build a Managed value

managed_ :: MonadManaged m => (forall r. IO r -> IO r) -> m () Source #

Like managed but for resource-less operations.

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

Run a Managed computation, enforcing that no acquired resources leak

# Re-exports

Control.Monad.IO.Class re-exports MonadIO

class Monad m => MonadIO (m :: Type -> Type) where #

Monads in which IO computations may be embedded. Any monad built by applying a sequence of monad transformers to the IO monad will be an instance of this class.

Instances should satisfy the following laws, which state that liftIO is a transformer of monads:

• liftIO . return = return
• liftIO (m >>= f) = liftIO m >>= (liftIO . f)

Methods

liftIO :: IO a -> m a #

Lift a computation from the IO monad.

Instances