X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FIO.hs;h=ad98a5ebf5460392c3e8523d65cffe74388a6f50;hb=7e0984fb4e3bf25e6050ab6fecc98211ad9f3ecd;hp=7295a2cd3e7b38563ffecdab606ee82cda0fe271;hpb=333e764afeb1c08b239caf9510e5e18a6c81ae31;p=ghc-base.git diff --git a/GHC/IO.hs b/GHC/IO.hs index 7295a2c..ad98a5e 100644 --- a/GHC/IO.hs +++ b/GHC/IO.hs @@ -36,7 +36,7 @@ module GHC.IO ( mask, mask_, uninterruptibleMask, uninterruptibleMask_, MaskingState(..), getMaskingState, block, unblock, blocked, unsafeUnmask, - onException, finally, evaluate + onException, bracket, finally, evaluate ) where import GHC.Base @@ -432,6 +432,18 @@ uninterruptibleMask io = do MaskedInterruptible -> blockUninterruptible $ io block MaskedUninterruptible -> io id +bracket + :: IO a -- ^ computation to run first (\"acquire resource\") + -> (a -> IO b) -- ^ computation to run last (\"release resource\") + -> (a -> IO c) -- ^ computation to run in-between + -> IO c -- returns the value from the in-between computation +bracket before after thing = + mask $ \restore -> do + a <- before + r <- restore (thing a) `onException` after a + _ <- after a + return r + finally :: IO a -- ^ computation to run first -> IO b -- ^ computation to run afterward (even if an exception -- was raised)