diff --git a/Control/Concurrent/Lifted.hs b/Control/Concurrent/Lifted.hs index 8231f98..a613b91 100644 --- a/Control/Concurrent/Lifted.hs +++ b/Control/Concurrent/Lifted.hs @@ -120,7 +120,7 @@ fork = liftBaseDiscard C.forkIO -- Note that, while the forked computation @m ()@ has access to the captured -- state, all its side-effects in @m@ are discarded. It is run only for its -- side-effects in 'IO'. -forkWithUnmask ∷ MonadBaseControl IO m ⇒ ((∀ α. m α → m α) → m ()) → m ThreadId +forkWithUnmask ∷ MonadBaseControl IO m ⇒ ((∀ a. m a → m a) → m ()) → m ThreadId forkWithUnmask f = liftBaseWith $ \runInIO → C.forkIOWithUnmask $ \unmask → void $ runInIO $ f $ liftBaseOp_ unmask @@ -152,7 +152,7 @@ forkOn = liftBaseDiscard ∘ C.forkOn -- Note that, while the forked computation @m ()@ has access to the captured -- state, all its side-effects in @m@ are discarded. It is run only for its -- side-effects in 'IO'. -forkOnWithUnmask ∷ MonadBaseControl IO m ⇒ Int → ((∀ α. m α → m α) → m ()) → m ThreadId +forkOnWithUnmask ∷ MonadBaseControl IO m ⇒ Int → ((∀ a. m a → m a) → m ()) → m ThreadId forkOnWithUnmask cap f = liftBaseWith $ \runInIO → C.forkOnWithUnmask cap $ \unmask → void $ runInIO $ f $ liftBaseOp_ unmask @@ -190,12 +190,12 @@ threadWaitWrite = liftBase ∘ C.threadWaitWrite {-# INLINABLE threadWaitWrite #-} -- | Generalized version of 'C.mergeIO'. -merge ∷ MonadBase IO m ⇒ [α] → [α] → m [α] +merge ∷ MonadBase IO m ⇒ [a] → [a] → m [a] merge xs ys = liftBase $ C.mergeIO xs ys {-# INLINABLE merge #-} -- | Generalized version of 'C.nmergeIO'. -nmerge ∷ MonadBase IO m ⇒ [[α]] → m [α] +nmerge ∷ MonadBase IO m ⇒ [[a]] → m [a] nmerge = liftBase ∘ C.nmergeIO {-# INLINABLE nmerge #-} @@ -214,11 +214,11 @@ isCurrentThreadBound = liftBase C.isCurrentThreadBound {-# INLINABLE isCurrentThreadBound #-} -- | Generalized version of 'C.runInBoundThread'. -runInBoundThread ∷ MonadBaseControl IO m ⇒ m α → m α +runInBoundThread ∷ MonadBaseControl IO m ⇒ m a → m a runInBoundThread = liftBaseOp_ C.runInBoundThread {-# INLINABLE runInBoundThread #-} -- | Generalized version of 'C.runInUnboundThread'. -runInUnboundThread ∷ MonadBaseControl IO m ⇒ m α → m α +runInUnboundThread ∷ MonadBaseControl IO m ⇒ m a → m a runInUnboundThread = liftBaseOp_ C.runInUnboundThread {-# INLINABLE runInUnboundThread #-} diff --git a/Control/Concurrent/MVar/Lifted.hs b/Control/Concurrent/MVar/Lifted.hs index e349606..e53aa9e 100644 --- a/Control/Concurrent/MVar/Lifted.hs +++ b/Control/Concurrent/MVar/Lifted.hs @@ -81,62 +81,62 @@ import Control.Monad.Trans.Control ( MonadBaseControl -------------------------------------------------------------------------------- -- | Generalized version of 'MVar.newEmptyMVar'. -newEmptyMVar ∷ MonadBase IO m ⇒ m (MVar α) +newEmptyMVar ∷ MonadBase IO m ⇒ m (MVar a) newEmptyMVar = liftBase MVar.newEmptyMVar {-# INLINABLE newEmptyMVar #-} -- | Generalized version of 'MVar.newMVar'. -newMVar ∷ MonadBase IO m ⇒ α → m (MVar α) +newMVar ∷ MonadBase IO m ⇒ a → m (MVar a) newMVar = liftBase ∘ MVar.newMVar {-# INLINABLE newMVar #-} -- | Generalized version of 'MVar.takeMVar'. -takeMVar ∷ MonadBase IO m ⇒ MVar α → m α +takeMVar ∷ MonadBase IO m ⇒ MVar a → m a takeMVar = liftBase ∘ MVar.takeMVar {-# INLINABLE takeMVar #-} -- | Generalized version of 'MVar.putMVar'. -putMVar ∷ MonadBase IO m ⇒ MVar α → α → m () +putMVar ∷ MonadBase IO m ⇒ MVar a → a → m () putMVar mv x = liftBase $ MVar.putMVar mv x {-# INLINABLE putMVar #-} -- | Generalized version of 'MVar.readMVar'. -readMVar ∷ MonadBase IO m ⇒ MVar α → m α +readMVar ∷ MonadBase IO m ⇒ MVar a → m a readMVar = liftBase ∘ MVar.readMVar {-# INLINABLE readMVar #-} -- | Generalized version of 'MVar.swapMVar'. -swapMVar ∷ MonadBase IO m ⇒ MVar α → α → m α +swapMVar ∷ MonadBase IO m ⇒ MVar a → a → m a swapMVar mv x = liftBase $ MVar.swapMVar mv x {-# INLINABLE swapMVar #-} -- | Generalized version of 'MVar.tryTakeMVar'. -tryTakeMVar ∷ MonadBase IO m ⇒ MVar α → m (Maybe α) +tryTakeMVar ∷ MonadBase IO m ⇒ MVar a → m (Maybe a) tryTakeMVar = liftBase ∘ MVar.tryTakeMVar {-# INLINABLE tryTakeMVar #-} -- | Generalized version of 'MVar.tryPutMVar'. -tryPutMVar ∷ MonadBase IO m ⇒ MVar α → α → m Bool +tryPutMVar ∷ MonadBase IO m ⇒ MVar a → a → m Bool tryPutMVar mv x = liftBase $ MVar.tryPutMVar mv x {-# INLINABLE tryPutMVar #-} -- | Generalized version of 'MVar.isEmptyMVar'. -isEmptyMVar ∷ MonadBase IO m ⇒ MVar α → m Bool +isEmptyMVar ∷ MonadBase IO m ⇒ MVar a → m Bool isEmptyMVar = liftBase ∘ MVar.isEmptyMVar {-# INLINABLE isEmptyMVar #-} -- | Generalized version of 'MVar.withMVar'. -withMVar ∷ MonadBaseControl IO m ⇒ MVar α → (α → m β) → m β +withMVar ∷ MonadBaseControl IO m ⇒ MVar a → (a → m b) → m b withMVar = liftBaseOp ∘ MVar.withMVar {-# INLINABLE withMVar #-} -- | Generalized version of 'MVar.modifyMVar_'. -modifyMVar_ ∷ (MonadBaseControl IO m) ⇒ MVar α → (α → m α) → m () +modifyMVar_ ∷ (MonadBaseControl IO m) ⇒ MVar a → (a → m a) → m () modifyMVar_ mv = modifyMVar mv ∘ (fmap (, ()) ∘) {-# INLINABLE modifyMVar_ #-} -- | Generalized version of 'MVar.modifyMVar'. -modifyMVar ∷ (MonadBaseControl IO m) ⇒ MVar α → (α → m (α, β)) → m β +modifyMVar ∷ (MonadBaseControl IO m) ⇒ MVar a → (a → m (a, b)) → m b #if MIN_VERSION_base(4,3,0) modifyMVar mv f = control $ \runInIO -> mask $ \restore → do @@ -173,6 +173,6 @@ modifyMVar mv f = control $ \runInIO -> block $ do -- -- Note any monadic side effects in @m@ of the \"finalizer\" computation are -- discarded. -addMVarFinalizer ∷ MonadBaseControl IO m ⇒ MVar α → m () → m () +addMVarFinalizer ∷ MonadBaseControl IO m ⇒ MVar a → m () → m () addMVarFinalizer = liftBaseDiscard ∘ MVar.addMVarFinalizer {-# INLINABLE addMVarFinalizer #-} diff --git a/Control/Exception/Lifted.hs b/Control/Exception/Lifted.hs index 6a51d4c..f4ea498 100644 --- a/Control/Exception/Lifted.hs +++ b/Control/Exception/Lifted.hs @@ -127,12 +127,12 @@ import Control.Monad.Trans.Control ( liftBaseOp ) -------------------------------------------------------------------------------- -- |Generalized version of 'E.throwIO'. -throwIO ∷ (MonadBase IO m, Exception e) ⇒ e → m α +throwIO ∷ (MonadBase IO m, Exception e) ⇒ e → m a throwIO = liftBase ∘ E.throwIO {-# INLINABLE throwIO #-} -- |Generalized version of 'E.ioError'. -ioError ∷ MonadBase IO m ⇒ IOError → m α +ioError ∷ MonadBase IO m ⇒ IOError → m a ioError = liftBase ∘ E.ioError {-# INLINABLE ioError #-} @@ -143,16 +143,16 @@ ioError = liftBase ∘ E.ioError -- |Generalized version of 'E.catch'. catch ∷ (MonadBaseControl IO m, Exception e) - ⇒ m α -- ^ The computation to run - → (e → m α) -- ^ Handler to invoke if an exception is raised - → m α + ⇒ m a -- ^ The computation to run + → (e → m a) -- ^ Handler to invoke if an exception is raised + → m a catch a handler = control $ \runInIO → E.catch (runInIO a) (\e → runInIO $ handler e) {-# INLINABLE catch #-} -- |Generalized version of 'E.catches'. -catches ∷ MonadBaseControl IO m ⇒ m α → [Handler m α] → m α +catches ∷ MonadBaseControl IO m ⇒ m a → [Handler m a] → m a catches a handlers = control $ \runInIO → E.catches (runInIO a) [ E.Handler $ \e → runInIO $ handler e @@ -161,14 +161,14 @@ catches a handlers = control $ \runInIO → {-# INLINABLE catches #-} -- |Generalized version of 'E.Handler'. -data Handler m α = ∀ e. Exception e ⇒ Handler (e → m α) +data Handler m a = ∀ e. Exception e ⇒ Handler (e → m a) -- |Generalized version of 'E.catchJust'. catchJust ∷ (MonadBaseControl IO m, Exception e) - ⇒ (e → Maybe β) -- ^ Predicate to select exceptions - → m α -- ^ Computation to run - → (β → m α) -- ^ Handler - → m α + ⇒ (e → Maybe b) -- ^ Predicate to select exceptions + → m a -- ^ Computation to run + → (b → m a) -- ^ Handler + → m a catchJust p a handler = control $ \runInIO → E.catchJust p (runInIO a) @@ -181,7 +181,7 @@ catchJust p a handler = control $ \runInIO → -------------------------------------------------------------------------------- -- |Generalized version of 'E.handle'. -handle ∷ (MonadBaseControl IO m, Exception e) ⇒ (e → m α) → m α → m α +handle ∷ (MonadBaseControl IO m, Exception e) ⇒ (e → m a) → m a → m a handle handler a = control $ \runInIO → E.handle (\e → runInIO (handler e)) (runInIO a) @@ -189,7 +189,7 @@ handle handler a = control $ \runInIO → -- |Generalized version of 'E.handleJust'. handleJust ∷ (MonadBaseControl IO m, Exception e) - ⇒ (e → Maybe β) → (β → m α) → m α → m α + ⇒ (e → Maybe b) → (b → m a) → m a → m a handleJust p handler a = control $ \runInIO → E.handleJust p (\e → runInIO (handler e)) (runInIO a) @@ -199,17 +199,17 @@ handleJust p handler a = control $ \runInIO → -- ** The @try@ functions -------------------------------------------------------------------------------- -sequenceEither ∷ MonadBaseControl IO m ⇒ Either e (StM m α) → m (Either e α) +sequenceEither ∷ MonadBaseControl IO m ⇒ Either e (StM m a) → m (Either e a) sequenceEither = either (return ∘ Left) (liftM Right ∘ restoreM) {-# INLINE sequenceEither #-} -- |Generalized version of 'E.try'. -try ∷ (MonadBaseControl IO m, Exception e) ⇒ m α → m (Either e α) +try ∷ (MonadBaseControl IO m, Exception e) ⇒ m a → m (Either e a) try m = liftBaseWith (\runInIO → E.try (runInIO m)) >>= sequenceEither {-# INLINABLE try #-} -- |Generalized version of 'E.tryJust'. -tryJust ∷ (MonadBaseControl IO m, Exception e) ⇒ (e → Maybe β) → m α → m (Either β α) +tryJust ∷ (MonadBaseControl IO m, Exception e) ⇒ (e → Maybe b) → m a → m (Either b a) tryJust p m = liftBaseWith (\runInIO → E.tryJust p (runInIO m)) >>= sequenceEither {-# INLINABLE tryJust #-} @@ -219,7 +219,7 @@ tryJust p m = liftBaseWith (\runInIO → E.tryJust p (runInIO m)) >>= sequenceEi -------------------------------------------------------------------------------- -- |Generalized version of 'E.evaluate'. -evaluate ∷ MonadBase IO m ⇒ α → m α +evaluate ∷ MonadBase IO m ⇒ a → m a evaluate = liftBase ∘ E.evaluate {-# INLINABLE evaluate #-} @@ -230,28 +230,28 @@ evaluate = liftBase ∘ E.evaluate #if MIN_VERSION_base(4,3,0) -- |Generalized version of 'E.mask'. -mask ∷ MonadBaseControl IO m ⇒ ((∀ α. m α → m α) → m β) → m β +mask ∷ MonadBaseControl IO m ⇒ ((∀ a. m a → m a) → m b) → m b mask = liftBaseOp E.mask ∘ liftRestore {-# INLINABLE mask #-} liftRestore ∷ MonadBaseControl IO m - ⇒ ((∀ α. m α → m α) → β) - → ((∀ α. IO α → IO α) → β) + ⇒ ((∀ a. m a → m a) → b) + → ((∀ a. IO a → IO a) → b) liftRestore f r = f $ liftBaseOp_ r {-# INLINE liftRestore #-} -- |Generalized version of 'E.mask_'. -mask_ ∷ MonadBaseControl IO m ⇒ m α → m α +mask_ ∷ MonadBaseControl IO m ⇒ m a → m a mask_ = liftBaseOp_ E.mask_ {-# INLINABLE mask_ #-} -- |Generalized version of 'E.uninterruptibleMask'. -uninterruptibleMask ∷ MonadBaseControl IO m ⇒ ((∀ α. m α → m α) → m β) → m β +uninterruptibleMask ∷ MonadBaseControl IO m ⇒ ((∀ a. m a → m a) → m b) → m b uninterruptibleMask = liftBaseOp E.uninterruptibleMask ∘ liftRestore {-# INLINABLE uninterruptibleMask #-} -- |Generalized version of 'E.uninterruptibleMask_'. -uninterruptibleMask_ ∷ MonadBaseControl IO m ⇒ m α → m α +uninterruptibleMask_ ∷ MonadBaseControl IO m ⇒ m a → m a uninterruptibleMask_ = liftBaseOp_ E.uninterruptibleMask_ {-# INLINABLE uninterruptibleMask_ #-} @@ -261,12 +261,12 @@ getMaskingState = liftBase E.getMaskingState {-# INLINABLE getMaskingState #-} #else -- |Generalized version of 'E.block'. -block ∷ MonadBaseControl IO m ⇒ m α → m α +block ∷ MonadBaseControl IO m ⇒ m a → m a block = liftBaseOp_ E.block {-# INLINABLE block #-} -- |Generalized version of 'E.unblock'. -unblock ∷ MonadBaseControl IO m ⇒ m α → m α +unblock ∷ MonadBaseControl IO m ⇒ m a → m a unblock = liftBaseOp_ E.unblock {-# INLINABLE unblock #-} #endif @@ -294,10 +294,10 @@ blocked = liftBase E.blocked -- -- @'liftBaseOp' ('E.bracket' acquire release)@ bracket ∷ MonadBaseControl IO m - ⇒ m α -- ^ computation to run first (\"acquire resource\") - → (α → m β) -- ^ computation to run last (\"release resource\") - → (α → m γ) -- ^ computation to run in-between - → m γ + ⇒ m a -- ^ computation to run first (\"acquire resource\") + → (a → m b) -- ^ computation to run last (\"release resource\") + → (a → m c) -- ^ computation to run in-between + → m c bracket before after thing = control $ \runInIO → E.bracket (runInIO before) (\st → runInIO $ restoreM st >>= after) @@ -315,10 +315,10 @@ bracket before after thing = control $ \runInIO → -- -- @'liftBaseOp_' ('E.bracket_' acquire release)@ bracket_ ∷ MonadBaseControl IO m - ⇒ m α -- ^ computation to run first (\"acquire resource\") - → m β -- ^ computation to run last (\"release resource\") - → m γ -- ^ computation to run in-between - → m γ + ⇒ m a -- ^ computation to run first (\"acquire resource\") + → m b -- ^ computation to run last (\"release resource\") + → m c -- ^ computation to run in-between + → m c bracket_ before after thing = control $ \runInIO → E.bracket_ (runInIO before) (runInIO after) @@ -333,10 +333,10 @@ bracket_ before after thing = control $ \runInIO → -- -- @'liftBaseOp' ('E.bracketOnError' acquire release)@ bracketOnError ∷ MonadBaseControl IO m - ⇒ m α -- ^ computation to run first (\"acquire resource\") - → (α → m β) -- ^ computation to run last (\"release resource\") - → (α → m γ) -- ^ computation to run in-between - → m γ + ⇒ m a -- ^ computation to run first (\"acquire resource\") + → (a → m b) -- ^ computation to run last (\"release resource\") + → (a → m c) -- ^ computation to run in-between + → m c bracketOnError before after thing = control $ \runInIO → E.bracketOnError (runInIO before) @@ -352,9 +352,9 @@ bracketOnError before after thing = -- |Generalized version of 'E.finally'. Note, any monadic side -- effects in @m@ of the \"afterward\" computation will be discarded. finally ∷ MonadBaseControl IO m - ⇒ m α -- ^ computation to run first - → m β -- ^ computation to run afterward (even if an exception was raised) - → m α + ⇒ m a -- ^ computation to run first + → m b -- ^ computation to run afterward (even if an exception was raised) + → m a finally a sequel = control $ \runInIO → E.finally (runInIO a) (runInIO sequel) @@ -362,7 +362,7 @@ finally a sequel = control $ \runInIO → -- |Generalized version of 'E.onException'. Note, any monadic side -- effects in @m@ of the \"afterward\" computation will be discarded. -onException ∷ MonadBaseControl IO m ⇒ m α → m β → m α +onException ∷ MonadBaseControl IO m ⇒ m a → m b → m a onException m what = control $ \runInIO → E.onException (runInIO m) (runInIO what) diff --git a/System/Timeout/Lifted.hs b/System/Timeout/Lifted.hs index 3ab8f55..e65b629 100644 --- a/System/Timeout/Lifted.hs +++ b/System/Timeout/Lifted.hs @@ -37,7 +37,7 @@ import Control.Monad.Trans.Control ( MonadBaseControl, restoreM, liftBaseWith ) -- Note that when the given computation times out any side effects of @m@ are -- discarded. When the computation completes within the given time the -- side-effects are restored on return. -timeout ∷ MonadBaseControl IO m ⇒ Int → m α → m (Maybe α) +timeout ∷ MonadBaseControl IO m ⇒ Int → m a → m (Maybe a) timeout t m = liftBaseWith (\runInIO → T.timeout t (runInIO m)) >>= maybe (return Nothing) (liftM Just ∘ restoreM) {-# INLINABLE timeout #-} diff --git a/lifted-base.cabal b/lifted-base.cabal index 4bc48f5..f52f7ba 100644 --- a/lifted-base.cabal +++ b/lifted-base.cabal @@ -1,5 +1,5 @@ Name: lifted-base -Version: 0.1.0.3 +Version: 0.1.0.4 Synopsis: lifted IO operations from the base library License: BSD3 License-file: LICENSE