Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

# Managed

A managed resource that you acquire using `with`

## Instances

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)

## Instances

MonadManaged Managed | |

Defined in Control.Monad.Managed | |

MonadManaged m => MonadManaged (MaybeT m) | |

Defined in Control.Monad.Managed | |

MonadManaged m => MonadManaged (IdentityT m) | |

Defined in Control.Monad.Managed | |

MonadManaged m => MonadManaged (ExceptT e m) | |

Defined in Control.Monad.Managed | |

(Monoid w, MonadManaged m) => MonadManaged (WriterT w m) | |

Defined in Control.Monad.Managed | |

MonadManaged m => MonadManaged (StateT s m) | |

Defined in Control.Monad.Managed | |

MonadManaged m => MonadManaged (StateT s m) | |

Defined in Control.Monad.Managed | |

(Monoid w, MonadManaged m) => MonadManaged (WriterT w m) | |

Defined in Control.Monad.Managed | |

MonadManaged m => MonadManaged (ReaderT r m) | |

Defined in Control.Monad.Managed | |

MonadManaged m => MonadManaged (ContT r m) | |

Defined in Control.Monad.Managed | |

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

Defined in Control.Monad.Managed | |

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

Defined in Control.Monad.Managed |