packages feed

managed 1.0.5 → 1.0.6

raw patch · 2 files changed

+39/−4 lines, 2 filesdep +semigroupsdep ~basePVP ok

version bump matches the API change (PVP)

Dependencies added: semigroups

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Control.Monad.Managed: instance Data.Semigroup.Semigroup a => Data.Semigroup.Semigroup (Control.Monad.Managed.Managed a)

Files

managed.cabal view
@@ -1,5 +1,5 @@ Name: managed-Version: 1.0.5+Version: 1.0.6 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3@@ -35,6 +35,9 @@     Build-Depends:         base              >= 4.5     && < 5  ,         transformers      >= 0.2.0.0 && < 0.6+    if !impl(ghc >= 8.0)+      Build-Depends:+        semigroups        >= 0.16    && < 0.19     Exposed-Modules:         Control.Monad.Managed,         Control.Monad.Managed.Safe
src/Control/Monad/Managed.hs view
@@ -80,7 +80,7 @@  > import Control.Monad > import Control.Monad.Managed-> +> > main = runManaged (forever (liftIO (print 1)))      If you need to acquire a resource for a long-lived loop, you can instead@@ -114,9 +114,13 @@ import Control.Applicative (liftA2) #else import Control.Applicative-import Data.Monoid+import Data.Monoid (Monoid(..)) #endif +#if !(MIN_VERSION_base(4,11,0))+import Data.Semigroup (Semigroup(..))+#endif+ import qualified Control.Monad.Trans.Cont          as Cont #if MIN_VERSION_transformers(0,4,0) import qualified Control.Monad.Trans.Except        as Except@@ -162,10 +166,15 @@         a <- m         return_ a ) +instance Semigroup a => Semigroup (Managed a) where+    (<>) = liftA2 (<>)+ instance Monoid a => Monoid (Managed a) where     mempty = pure mempty +#if !(MIN_VERSION_base(4,11,0))     mappend = liftA2 mappend+#endif  instance Num a => Num (Managed a) where     fromInteger = pure . fromInteger@@ -259,7 +268,30 @@ managed_ :: (forall r. IO r -> IO r) -> Managed () managed_ f = managed $ \g -> f $ g () --- | Acquire a `Managed` value+{-| 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.+-} with :: Managed a -> (a -> IO r) -> IO r with = (>>-)