{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE QuantifiedConstraints #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-} module Ouroboros.Consensus.Util.EarlyExit ( exitEarly , withEarlyExit , withEarlyExit_ -- * Re-exports , lift -- * opaque , WithEarlyExit ) where import Control.Applicative import Control.Concurrent.Class.MonadMVar import Control.Monad import Control.Monad.Class.MonadAsync import Control.Monad.Class.MonadEventlog import Control.Monad.Class.MonadFork import Control.Monad.Class.MonadSay import Control.Monad.Class.MonadST import Control.Monad.Class.MonadSTM.Internal import Control.Monad.Class.MonadThrow import Control.Monad.Class.MonadTime import Control.Monad.Class.MonadTime.SI import Control.Monad.Class.MonadTimer import qualified Control.Monad.Class.MonadTimer.SI as TimerSI import Control.Monad.Trans.Class import Control.Monad.Trans.Maybe import Data.Function (on) import Data.Proxy import NoThunks.Class (NoThunks (..)) import Ouroboros.Consensus.Util ((.:)) import Ouroboros.Consensus.Util.IOLike (IOLike (..), PrimMonad (..), StrictSVar, StrictTVar, castStrictSVar, castStrictTVar) import Ouroboros.Consensus.Util.NormalForm.StrictMVar (StrictMVar) {------------------------------------------------------------------------------- Basic definitions -------------------------------------------------------------------------------} newtype WithEarlyExit m a = WithEarlyExit { forall (m :: * -> *) a. WithEarlyExit m a -> MaybeT m a unWithEarlyExit :: MaybeT m a } deriving ( (forall a b. (a -> b) -> WithEarlyExit m a -> WithEarlyExit m b) -> (forall a b. a -> WithEarlyExit m b -> WithEarlyExit m a) -> Functor (WithEarlyExit m) forall a b. a -> WithEarlyExit m b -> WithEarlyExit m a forall a b. (a -> b) -> WithEarlyExit m a -> WithEarlyExit m b forall (m :: * -> *) a b. Functor m => a -> WithEarlyExit m b -> WithEarlyExit m a forall (m :: * -> *) a b. Functor m => (a -> b) -> WithEarlyExit m a -> WithEarlyExit m b forall (f :: * -> *). (forall a b. (a -> b) -> f a -> f b) -> (forall a b. a -> f b -> f a) -> Functor f $cfmap :: forall (m :: * -> *) a b. Functor m => (a -> b) -> WithEarlyExit m a -> WithEarlyExit m b fmap :: forall a b. (a -> b) -> WithEarlyExit m a -> WithEarlyExit m b $c<$ :: forall (m :: * -> *) a b. Functor m => a -> WithEarlyExit m b -> WithEarlyExit m a <$ :: forall a b. a -> WithEarlyExit m b -> WithEarlyExit m a Functor , Functor (WithEarlyExit m) Functor (WithEarlyExit m) => (forall a. a -> WithEarlyExit m a) -> (forall a b. WithEarlyExit m (a -> b) -> WithEarlyExit m a -> WithEarlyExit m b) -> (forall a b c. (a -> b -> c) -> WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m c) -> (forall a b. WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m b) -> (forall a b. WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m a) -> Applicative (WithEarlyExit m) forall a. a -> WithEarlyExit m a forall a b. WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m a forall a b. WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m b forall a b. WithEarlyExit m (a -> b) -> WithEarlyExit m a -> WithEarlyExit m b forall a b c. (a -> b -> c) -> WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m c forall (m :: * -> *). Monad m => Functor (WithEarlyExit m) forall (m :: * -> *) a. Monad m => a -> WithEarlyExit m a forall (m :: * -> *) a b. Monad m => WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m a forall (m :: * -> *) a b. Monad m => WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m b forall (m :: * -> *) a b. Monad m => WithEarlyExit m (a -> b) -> WithEarlyExit m a -> WithEarlyExit m b forall (m :: * -> *) a b c. Monad m => (a -> b -> c) -> WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m c forall (f :: * -> *). Functor f => (forall a. a -> f a) -> (forall a b. f (a -> b) -> f a -> f b) -> (forall a b c. (a -> b -> c) -> f a -> f b -> f c) -> (forall a b. f a -> f b -> f b) -> (forall a b. f a -> f b -> f a) -> Applicative f $cpure :: forall (m :: * -> *) a. Monad m => a -> WithEarlyExit m a pure :: forall a. a -> WithEarlyExit m a $c<*> :: forall (m :: * -> *) a b. Monad m => WithEarlyExit m (a -> b) -> WithEarlyExit m a -> WithEarlyExit m b <*> :: forall a b. WithEarlyExit m (a -> b) -> WithEarlyExit m a -> WithEarlyExit m b $cliftA2 :: forall (m :: * -> *) a b c. Monad m => (a -> b -> c) -> WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m c liftA2 :: forall a b c. (a -> b -> c) -> WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m c $c*> :: forall (m :: * -> *) a b. Monad m => WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m b *> :: forall a b. WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m b $c<* :: forall (m :: * -> *) a b. Monad m => WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m a <* :: forall a b. WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m a Applicative , Applicative (WithEarlyExit m) Applicative (WithEarlyExit m) => (forall a. WithEarlyExit m a) -> (forall a. WithEarlyExit m a -> WithEarlyExit m a -> WithEarlyExit m a) -> (forall a. WithEarlyExit m a -> WithEarlyExit m [a]) -> (forall a. WithEarlyExit m a -> WithEarlyExit m [a]) -> Alternative (WithEarlyExit m) forall a. WithEarlyExit m a forall a. WithEarlyExit m a -> WithEarlyExit m [a] forall a. WithEarlyExit m a -> WithEarlyExit m a -> WithEarlyExit m a forall (m :: * -> *). Monad m => Applicative (WithEarlyExit m) forall (m :: * -> *) a. Monad m => WithEarlyExit m a forall (m :: * -> *) a. Monad m => WithEarlyExit m a -> WithEarlyExit m [a] forall (m :: * -> *) a. Monad m => WithEarlyExit m a -> WithEarlyExit m a -> WithEarlyExit m a forall (f :: * -> *). Applicative f => (forall a. f a) -> (forall a. f a -> f a -> f a) -> (forall a. f a -> f [a]) -> (forall a. f a -> f [a]) -> Alternative f $cempty :: forall (m :: * -> *) a. Monad m => WithEarlyExit m a empty :: forall a. WithEarlyExit m a $c<|> :: forall (m :: * -> *) a. Monad m => WithEarlyExit m a -> WithEarlyExit m a -> WithEarlyExit m a <|> :: forall a. WithEarlyExit m a -> WithEarlyExit m a -> WithEarlyExit m a $csome :: forall (m :: * -> *) a. Monad m => WithEarlyExit m a -> WithEarlyExit m [a] some :: forall a. WithEarlyExit m a -> WithEarlyExit m [a] $cmany :: forall (m :: * -> *) a. Monad m => WithEarlyExit m a -> WithEarlyExit m [a] many :: forall a. WithEarlyExit m a -> WithEarlyExit m [a] Alternative , Applicative (WithEarlyExit m) Applicative (WithEarlyExit m) => (forall a b. WithEarlyExit m a -> (a -> WithEarlyExit m b) -> WithEarlyExit m b) -> (forall a b. WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m b) -> (forall a. a -> WithEarlyExit m a) -> Monad (WithEarlyExit m) forall a. a -> WithEarlyExit m a forall a b. WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m b forall a b. WithEarlyExit m a -> (a -> WithEarlyExit m b) -> WithEarlyExit m b forall (m :: * -> *). Monad m => Applicative (WithEarlyExit m) forall (m :: * -> *) a. Monad m => a -> WithEarlyExit m a forall (m :: * -> *) a b. Monad m => WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m b forall (m :: * -> *) a b. Monad m => WithEarlyExit m a -> (a -> WithEarlyExit m b) -> WithEarlyExit m b forall (m :: * -> *). Applicative m => (forall a b. m a -> (a -> m b) -> m b) -> (forall a b. m a -> m b -> m b) -> (forall a. a -> m a) -> Monad m $c>>= :: forall (m :: * -> *) a b. Monad m => WithEarlyExit m a -> (a -> WithEarlyExit m b) -> WithEarlyExit m b >>= :: forall a b. WithEarlyExit m a -> (a -> WithEarlyExit m b) -> WithEarlyExit m b $c>> :: forall (m :: * -> *) a b. Monad m => WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m b >> :: forall a b. WithEarlyExit m a -> WithEarlyExit m b -> WithEarlyExit m b $creturn :: forall (m :: * -> *) a. Monad m => a -> WithEarlyExit m a return :: forall a. a -> WithEarlyExit m a Monad , (forall (m :: * -> *). Monad m => Monad (WithEarlyExit m)) => (forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a) -> MonadTrans WithEarlyExit forall (m :: * -> *). Monad m => Monad (WithEarlyExit m) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *). (forall (m :: * -> *). Monad m => Monad (t m)) => (forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t $clift :: forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a lift :: forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a MonadTrans , Monad (WithEarlyExit m) Alternative (WithEarlyExit m) (Alternative (WithEarlyExit m), Monad (WithEarlyExit m)) => (forall a. WithEarlyExit m a) -> (forall a. WithEarlyExit m a -> WithEarlyExit m a -> WithEarlyExit m a) -> MonadPlus (WithEarlyExit m) forall a. WithEarlyExit m a forall a. WithEarlyExit m a -> WithEarlyExit m a -> WithEarlyExit m a forall (m :: * -> *). Monad m => Monad (WithEarlyExit m) forall (m :: * -> *). Monad m => Alternative (WithEarlyExit m) forall (m :: * -> *) a. Monad m => WithEarlyExit m a forall (m :: * -> *) a. Monad m => WithEarlyExit m a -> WithEarlyExit m a -> WithEarlyExit m a forall (m :: * -> *). (Alternative m, Monad m) => (forall a. m a) -> (forall a. m a -> m a -> m a) -> MonadPlus m $cmzero :: forall (m :: * -> *) a. Monad m => WithEarlyExit m a mzero :: forall a. WithEarlyExit m a $cmplus :: forall (m :: * -> *) a. Monad m => WithEarlyExit m a -> WithEarlyExit m a -> WithEarlyExit m a mplus :: forall a. WithEarlyExit m a -> WithEarlyExit m a -> WithEarlyExit m a MonadPlus ) instance NoThunks (StrictTVar m a) => NoThunks (StrictTVar (WithEarlyExit m) a) where showTypeOf :: Proxy (StrictTVar (WithEarlyExit m) a) -> String showTypeOf Proxy (StrictTVar (WithEarlyExit m) a) _ = String "StrictTVar (WithEarlyExit m)" wNoThunks :: Context -> StrictTVar (WithEarlyExit m) a -> IO (Maybe ThunkInfo) wNoThunks Context ctxt StrictTVar (WithEarlyExit m) a tv = do Context -> StrictTVar m a -> IO (Maybe ThunkInfo) forall a. NoThunks a => Context -> a -> IO (Maybe ThunkInfo) wNoThunks Context ctxt (StrictTVar (WithEarlyExit m) a -> StrictTVar m a forall (m :: * -> *) (n :: * -> *) a. (LazyTVar m ~ LazyTVar n) => StrictTVar m a -> StrictTVar n a castStrictTVar StrictTVar (WithEarlyExit m) a tv :: StrictTVar m a) instance NoThunks (StrictSVar m a) => NoThunks (StrictSVar (WithEarlyExit m) a) where showTypeOf :: Proxy (StrictSVar (WithEarlyExit m) a) -> String showTypeOf Proxy (StrictSVar (WithEarlyExit m) a) _ = String "StrictSVar (WithEarlyExit m)" wNoThunks :: Context -> StrictSVar (WithEarlyExit m) a -> IO (Maybe ThunkInfo) wNoThunks Context ctxt StrictSVar (WithEarlyExit m) a tv = do Context -> StrictSVar m a -> IO (Maybe ThunkInfo) forall a. NoThunks a => Context -> a -> IO (Maybe ThunkInfo) wNoThunks Context ctxt (StrictSVar (WithEarlyExit m) a -> StrictSVar m a forall (m :: * -> *) (n :: * -> *) a. (TMVar m ~ TMVar n, TVar m ~ TVar n) => StrictSVar m a -> StrictSVar n a castStrictSVar StrictSVar (WithEarlyExit m) a tv :: StrictSVar m a) -- | Internal only earlyExit :: m (Maybe a) -> WithEarlyExit m a earlyExit :: forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit = MaybeT m a -> WithEarlyExit m a forall (m :: * -> *) a. MaybeT m a -> WithEarlyExit m a WithEarlyExit (MaybeT m a -> WithEarlyExit m a) -> (m (Maybe a) -> MaybeT m a) -> m (Maybe a) -> WithEarlyExit m a forall b c a. (b -> c) -> (a -> b) -> a -> c . m (Maybe a) -> MaybeT m a forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a MaybeT withEarlyExit :: WithEarlyExit m a -> m (Maybe a) withEarlyExit :: forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit = MaybeT m a -> m (Maybe a) forall (m :: * -> *) a. MaybeT m a -> m (Maybe a) runMaybeT (MaybeT m a -> m (Maybe a)) -> (WithEarlyExit m a -> MaybeT m a) -> WithEarlyExit m a -> m (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . WithEarlyExit m a -> MaybeT m a forall (m :: * -> *) a. WithEarlyExit m a -> MaybeT m a unWithEarlyExit withEarlyExit_ :: Functor m => WithEarlyExit m () -> m () withEarlyExit_ :: forall (m :: * -> *). Functor m => WithEarlyExit m () -> m () withEarlyExit_ = (Maybe () -> ()) -> m (Maybe ()) -> m () forall a b. (a -> b) -> m a -> m b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Maybe () -> () collapse (m (Maybe ()) -> m ()) -> (WithEarlyExit m () -> m (Maybe ())) -> WithEarlyExit m () -> m () forall b c a. (b -> c) -> (a -> b) -> a -> c . WithEarlyExit m () -> m (Maybe ()) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit collapse :: Maybe () -> () collapse :: Maybe () -> () collapse Maybe () Nothing = () collapse (Just ()) = () exitEarly :: Applicative m => WithEarlyExit m a exitEarly :: forall (m :: * -> *) a. Applicative m => WithEarlyExit m a exitEarly = m (Maybe a) -> WithEarlyExit m a forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Maybe a) -> WithEarlyExit m a) -> m (Maybe a) -> WithEarlyExit m a forall a b. (a -> b) -> a -> b $ Maybe a -> m (Maybe a) forall a. a -> m a forall (f :: * -> *) a. Applicative f => a -> f a pure Maybe a forall a. Maybe a Nothing instance (forall a'. NoThunks (m a')) => NoThunks (WithEarlyExit m a) where showTypeOf :: Proxy (WithEarlyExit m a) -> String showTypeOf Proxy (WithEarlyExit m a) _p = String "WithEarlyExit " String -> String -> String forall a. [a] -> [a] -> [a] ++ Proxy (m a) -> String forall a. NoThunks a => Proxy a -> String showTypeOf (forall t. Proxy t forall {k} (t :: k). Proxy t Proxy @(m a)) wNoThunks :: Context -> WithEarlyExit m a -> IO (Maybe ThunkInfo) wNoThunks Context ctxt = Context -> m (Maybe a) -> IO (Maybe ThunkInfo) forall a. NoThunks a => Context -> a -> IO (Maybe ThunkInfo) wNoThunks Context ctxt (m (Maybe a) -> IO (Maybe ThunkInfo)) -> (WithEarlyExit m a -> m (Maybe a)) -> WithEarlyExit m a -> IO (Maybe ThunkInfo) forall b c a. (b -> c) -> (a -> b) -> a -> c . WithEarlyExit m a -> m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit {------------------------------------------------------------------------------- Instances for io-classes -------------------------------------------------------------------------------} instance MonadSTM m => MonadSTM (WithEarlyExit m) where type STM (WithEarlyExit m) = WithEarlyExit (STM m) atomically :: forall a. HasCallStack => STM (WithEarlyExit m) a -> WithEarlyExit m a atomically = m (Maybe a) -> WithEarlyExit m a forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Maybe a) -> WithEarlyExit m a) -> (WithEarlyExit (STM m) a -> m (Maybe a)) -> WithEarlyExit (STM m) a -> WithEarlyExit m a forall b c a. (b -> c) -> (a -> b) -> a -> c . STM m (Maybe a) -> m (Maybe a) forall a. HasCallStack => STM m a -> m a forall (m :: * -> *) a. (MonadSTM m, HasCallStack) => STM m a -> m a atomically (STM m (Maybe a) -> m (Maybe a)) -> (WithEarlyExit (STM m) a -> STM m (Maybe a)) -> WithEarlyExit (STM m) a -> m (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . WithEarlyExit (STM m) a -> STM m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit type TVar (WithEarlyExit m) = TVar m type TMVar (WithEarlyExit m) = TMVar m type TQueue (WithEarlyExit m) = TQueue m type TBQueue (WithEarlyExit m) = TBQueue m type TArray (WithEarlyExit m) = TArray m type TSem (WithEarlyExit m) = TSem m type TChan (WithEarlyExit m) = TChan m newTVar :: forall a. a -> STM (WithEarlyExit m) (TVar (WithEarlyExit m) a) newTVar = STM m (TVar m a) -> WithEarlyExit (STM m) (TVar m a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (TVar m a) -> WithEarlyExit (STM m) (TVar m a)) -> (a -> STM m (TVar m a)) -> a -> WithEarlyExit (STM m) (TVar m a) forall b c a. (b -> c) -> (a -> b) -> a -> c . a -> STM m (TVar m a) forall a. a -> STM m (TVar m a) forall (m :: * -> *) a. MonadSTM m => a -> STM m (TVar m a) newTVar readTVar :: forall a. TVar (WithEarlyExit m) a -> STM (WithEarlyExit m) a readTVar = STM m a -> WithEarlyExit (STM m) a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m a -> WithEarlyExit (STM m) a) -> (TVar m a -> STM m a) -> TVar m a -> WithEarlyExit (STM m) a forall b c a. (b -> c) -> (a -> b) -> a -> c . TVar m a -> STM m a forall a. TVar m a -> STM m a forall (m :: * -> *) a. MonadSTM m => TVar m a -> STM m a readTVar writeTVar :: forall a. TVar (WithEarlyExit m) a -> a -> STM (WithEarlyExit m) () writeTVar = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TVar m a -> a -> STM m ()) -> TVar m a -> a -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TVar m a -> a -> STM m () forall a. TVar m a -> a -> STM m () forall (m :: * -> *) a. MonadSTM m => TVar m a -> a -> STM m () writeTVar retry :: forall a. STM (WithEarlyExit m) a retry = STM m a -> WithEarlyExit (STM m) a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift STM m a forall a. STM m a forall (m :: * -> *) a. MonadSTM m => STM m a retry orElse :: forall a. STM (WithEarlyExit m) a -> STM (WithEarlyExit m) a -> STM (WithEarlyExit m) a orElse = (STM m (Maybe a) -> WithEarlyExit (STM m) a forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (STM m (Maybe a) -> WithEarlyExit (STM m) a) -> (STM m (Maybe a) -> STM m (Maybe a) -> STM m (Maybe a)) -> STM m (Maybe a) -> STM m (Maybe a) -> WithEarlyExit (STM m) a forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: STM m (Maybe a) -> STM m (Maybe a) -> STM m (Maybe a) forall a. STM m a -> STM m a -> STM m a forall (m :: * -> *) a. MonadSTM m => STM m a -> STM m a -> STM m a orElse) (STM m (Maybe a) -> STM m (Maybe a) -> WithEarlyExit (STM m) a) -> (WithEarlyExit (STM m) a -> STM m (Maybe a)) -> WithEarlyExit (STM m) a -> WithEarlyExit (STM m) a -> WithEarlyExit (STM m) a forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c `on` WithEarlyExit (STM m) a -> STM m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit newTMVar :: forall a. a -> STM (WithEarlyExit m) (TMVar (WithEarlyExit m) a) newTMVar = STM m (TMVar m a) -> WithEarlyExit (STM m) (TMVar m a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (TMVar m a) -> WithEarlyExit (STM m) (TMVar m a)) -> (a -> STM m (TMVar m a)) -> a -> WithEarlyExit (STM m) (TMVar m a) forall b c a. (b -> c) -> (a -> b) -> a -> c . a -> STM m (TMVar m a) forall a. a -> STM m (TMVar m a) forall (m :: * -> *) a. MonadSTM m => a -> STM m (TMVar m a) newTMVar newEmptyTMVar :: forall a. STM (WithEarlyExit m) (TMVar (WithEarlyExit m) a) newEmptyTMVar = STM m (TMVar m a) -> WithEarlyExit (STM m) (TMVar m a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift STM m (TMVar m a) forall a. STM m (TMVar m a) forall (m :: * -> *) a. MonadSTM m => STM m (TMVar m a) newEmptyTMVar takeTMVar :: forall a. TMVar (WithEarlyExit m) a -> STM (WithEarlyExit m) a takeTMVar = STM m a -> WithEarlyExit (STM m) a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m a -> WithEarlyExit (STM m) a) -> (TMVar m a -> STM m a) -> TMVar m a -> WithEarlyExit (STM m) a forall b c a. (b -> c) -> (a -> b) -> a -> c . TMVar m a -> STM m a forall a. TMVar m a -> STM m a forall (m :: * -> *) a. MonadSTM m => TMVar m a -> STM m a takeTMVar tryTakeTMVar :: forall a. TMVar (WithEarlyExit m) a -> STM (WithEarlyExit m) (Maybe a) tryTakeTMVar = STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a)) -> (TMVar m a -> STM m (Maybe a)) -> TMVar m a -> WithEarlyExit (STM m) (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . TMVar m a -> STM m (Maybe a) forall a. TMVar m a -> STM m (Maybe a) forall (m :: * -> *) a. MonadSTM m => TMVar m a -> STM m (Maybe a) tryTakeTMVar putTMVar :: forall a. TMVar (WithEarlyExit m) a -> a -> STM (WithEarlyExit m) () putTMVar = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TMVar m a -> a -> STM m ()) -> TMVar m a -> a -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TMVar m a -> a -> STM m () forall a. TMVar m a -> a -> STM m () forall (m :: * -> *) a. MonadSTM m => TMVar m a -> a -> STM m () putTMVar tryPutTMVar :: forall a. TMVar (WithEarlyExit m) a -> a -> STM (WithEarlyExit m) Bool tryPutTMVar = STM m Bool -> WithEarlyExit (STM m) Bool forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m Bool -> WithEarlyExit (STM m) Bool) -> (TMVar m a -> a -> STM m Bool) -> TMVar m a -> a -> WithEarlyExit (STM m) Bool forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TMVar m a -> a -> STM m Bool forall a. TMVar m a -> a -> STM m Bool forall (m :: * -> *) a. MonadSTM m => TMVar m a -> a -> STM m Bool tryPutTMVar readTMVar :: forall a. TMVar (WithEarlyExit m) a -> STM (WithEarlyExit m) a readTMVar = STM m a -> WithEarlyExit (STM m) a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m a -> WithEarlyExit (STM m) a) -> (TMVar m a -> STM m a) -> TMVar m a -> WithEarlyExit (STM m) a forall b c a. (b -> c) -> (a -> b) -> a -> c . TMVar m a -> STM m a forall a. TMVar m a -> STM m a forall (m :: * -> *) a. MonadSTM m => TMVar m a -> STM m a readTMVar writeTMVar :: forall a. TMVar (WithEarlyExit m) a -> a -> STM (WithEarlyExit m) () writeTMVar = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TMVar m a -> a -> STM m ()) -> TMVar m a -> a -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TMVar m a -> a -> STM m () forall a. TMVar m a -> a -> STM m () forall (m :: * -> *) a. MonadSTM m => TMVar m a -> a -> STM m () writeTMVar tryReadTMVar :: forall a. TMVar (WithEarlyExit m) a -> STM (WithEarlyExit m) (Maybe a) tryReadTMVar = STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a)) -> (TMVar m a -> STM m (Maybe a)) -> TMVar m a -> WithEarlyExit (STM m) (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . TMVar m a -> STM m (Maybe a) forall a. TMVar m a -> STM m (Maybe a) forall (m :: * -> *) a. MonadSTM m => TMVar m a -> STM m (Maybe a) tryReadTMVar swapTMVar :: forall a. TMVar (WithEarlyExit m) a -> a -> STM (WithEarlyExit m) a swapTMVar = STM m a -> WithEarlyExit (STM m) a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m a -> WithEarlyExit (STM m) a) -> (TMVar m a -> a -> STM m a) -> TMVar m a -> a -> WithEarlyExit (STM m) a forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TMVar m a -> a -> STM m a forall a. TMVar m a -> a -> STM m a forall (m :: * -> *) a. MonadSTM m => TMVar m a -> a -> STM m a swapTMVar isEmptyTMVar :: forall a. TMVar (WithEarlyExit m) a -> STM (WithEarlyExit m) Bool isEmptyTMVar = STM m Bool -> WithEarlyExit (STM m) Bool forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m Bool -> WithEarlyExit (STM m) Bool) -> (TMVar m a -> STM m Bool) -> TMVar m a -> WithEarlyExit (STM m) Bool forall b c a. (b -> c) -> (a -> b) -> a -> c . TMVar m a -> STM m Bool forall a. TMVar m a -> STM m Bool forall (m :: * -> *) a. MonadSTM m => TMVar m a -> STM m Bool isEmptyTMVar newTQueue :: forall a. STM (WithEarlyExit m) (TQueue (WithEarlyExit m) a) newTQueue = STM m (TQueue m a) -> WithEarlyExit (STM m) (TQueue m a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift STM m (TQueue m a) forall a. STM m (TQueue m a) forall (m :: * -> *) a. MonadSTM m => STM m (TQueue m a) newTQueue readTQueue :: forall a. TQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) a readTQueue = STM m a -> WithEarlyExit (STM m) a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m a -> WithEarlyExit (STM m) a) -> (TQueue m a -> STM m a) -> TQueue m a -> WithEarlyExit (STM m) a forall b c a. (b -> c) -> (a -> b) -> a -> c . TQueue m a -> STM m a forall a. TQueue m a -> STM m a forall (m :: * -> *) a. MonadSTM m => TQueue m a -> STM m a readTQueue tryReadTQueue :: forall a. TQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) (Maybe a) tryReadTQueue = STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a)) -> (TQueue m a -> STM m (Maybe a)) -> TQueue m a -> WithEarlyExit (STM m) (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . TQueue m a -> STM m (Maybe a) forall a. TQueue m a -> STM m (Maybe a) forall (m :: * -> *) a. MonadSTM m => TQueue m a -> STM m (Maybe a) tryReadTQueue peekTQueue :: forall a. TQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) a peekTQueue = STM m a -> WithEarlyExit (STM m) a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m a -> WithEarlyExit (STM m) a) -> (TQueue m a -> STM m a) -> TQueue m a -> WithEarlyExit (STM m) a forall b c a. (b -> c) -> (a -> b) -> a -> c . TQueue m a -> STM m a forall a. TQueue m a -> STM m a forall (m :: * -> *) a. MonadSTM m => TQueue m a -> STM m a peekTQueue tryPeekTQueue :: forall a. TQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) (Maybe a) tryPeekTQueue = STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a)) -> (TQueue m a -> STM m (Maybe a)) -> TQueue m a -> WithEarlyExit (STM m) (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . TQueue m a -> STM m (Maybe a) forall a. TQueue m a -> STM m (Maybe a) forall (m :: * -> *) a. MonadSTM m => TQueue m a -> STM m (Maybe a) tryPeekTQueue flushTQueue :: forall a. TQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) [a] flushTQueue = STM m [a] -> WithEarlyExit (STM m) [a] forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m [a] -> WithEarlyExit (STM m) [a]) -> (TQueue m a -> STM m [a]) -> TQueue m a -> WithEarlyExit (STM m) [a] forall b c a. (b -> c) -> (a -> b) -> a -> c . TQueue m a -> STM m [a] forall a. TQueue m a -> STM m [a] forall (m :: * -> *) a. MonadSTM m => TQueue m a -> STM m [a] flushTQueue writeTQueue :: forall a. TQueue (WithEarlyExit m) a -> a -> STM (WithEarlyExit m) () writeTQueue = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TQueue m a -> a -> STM m ()) -> TQueue m a -> a -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TQueue m a -> a -> STM m () forall a. TQueue m a -> a -> STM m () forall (m :: * -> *) a. MonadSTM m => TQueue m a -> a -> STM m () writeTQueue isEmptyTQueue :: forall a. TQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) Bool isEmptyTQueue = STM m Bool -> WithEarlyExit (STM m) Bool forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m Bool -> WithEarlyExit (STM m) Bool) -> (TQueue m a -> STM m Bool) -> TQueue m a -> WithEarlyExit (STM m) Bool forall b c a. (b -> c) -> (a -> b) -> a -> c . TQueue m a -> STM m Bool forall a. TQueue m a -> STM m Bool forall (m :: * -> *) a. MonadSTM m => TQueue m a -> STM m Bool isEmptyTQueue unGetTQueue :: forall a. TQueue (WithEarlyExit m) a -> a -> STM (WithEarlyExit m) () unGetTQueue = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TQueue m a -> a -> STM m ()) -> TQueue m a -> a -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TQueue m a -> a -> STM m () forall a. TQueue m a -> a -> STM m () forall (m :: * -> *) a. MonadSTM m => TQueue m a -> a -> STM m () unGetTQueue newTBQueue :: forall a. Natural -> STM (WithEarlyExit m) (TBQueue (WithEarlyExit m) a) newTBQueue = STM m (TBQueue m a) -> WithEarlyExit (STM m) (TBQueue m a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (TBQueue m a) -> WithEarlyExit (STM m) (TBQueue m a)) -> (Natural -> STM m (TBQueue m a)) -> Natural -> WithEarlyExit (STM m) (TBQueue m a) forall b c a. (b -> c) -> (a -> b) -> a -> c . Natural -> STM m (TBQueue m a) forall a. Natural -> STM m (TBQueue m a) forall (m :: * -> *) a. MonadSTM m => Natural -> STM m (TBQueue m a) newTBQueue readTBQueue :: forall a. TBQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) a readTBQueue = STM m a -> WithEarlyExit (STM m) a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m a -> WithEarlyExit (STM m) a) -> (TBQueue m a -> STM m a) -> TBQueue m a -> WithEarlyExit (STM m) a forall b c a. (b -> c) -> (a -> b) -> a -> c . TBQueue m a -> STM m a forall a. TBQueue m a -> STM m a forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m a readTBQueue tryReadTBQueue :: forall a. TBQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) (Maybe a) tryReadTBQueue = STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a)) -> (TBQueue m a -> STM m (Maybe a)) -> TBQueue m a -> WithEarlyExit (STM m) (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . TBQueue m a -> STM m (Maybe a) forall a. TBQueue m a -> STM m (Maybe a) forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m (Maybe a) tryReadTBQueue peekTBQueue :: forall a. TBQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) a peekTBQueue = STM m a -> WithEarlyExit (STM m) a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m a -> WithEarlyExit (STM m) a) -> (TBQueue m a -> STM m a) -> TBQueue m a -> WithEarlyExit (STM m) a forall b c a. (b -> c) -> (a -> b) -> a -> c . TBQueue m a -> STM m a forall a. TBQueue m a -> STM m a forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m a peekTBQueue tryPeekTBQueue :: forall a. TBQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) (Maybe a) tryPeekTBQueue = STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a)) -> (TBQueue m a -> STM m (Maybe a)) -> TBQueue m a -> WithEarlyExit (STM m) (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . TBQueue m a -> STM m (Maybe a) forall a. TBQueue m a -> STM m (Maybe a) forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m (Maybe a) tryPeekTBQueue flushTBQueue :: forall a. TBQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) [a] flushTBQueue = STM m [a] -> WithEarlyExit (STM m) [a] forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m [a] -> WithEarlyExit (STM m) [a]) -> (TBQueue m a -> STM m [a]) -> TBQueue m a -> WithEarlyExit (STM m) [a] forall b c a. (b -> c) -> (a -> b) -> a -> c . TBQueue m a -> STM m [a] forall a. TBQueue m a -> STM m [a] forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m [a] flushTBQueue writeTBQueue :: forall a. TBQueue (WithEarlyExit m) a -> a -> STM (WithEarlyExit m) () writeTBQueue = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TBQueue m a -> a -> STM m ()) -> TBQueue m a -> a -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TBQueue m a -> a -> STM m () forall a. TBQueue m a -> a -> STM m () forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> a -> STM m () writeTBQueue lengthTBQueue :: forall a. TBQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) Natural lengthTBQueue = STM m Natural -> WithEarlyExit (STM m) Natural forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m Natural -> WithEarlyExit (STM m) Natural) -> (TBQueue m a -> STM m Natural) -> TBQueue m a -> WithEarlyExit (STM m) Natural forall b c a. (b -> c) -> (a -> b) -> a -> c . TBQueue m a -> STM m Natural forall a. TBQueue m a -> STM m Natural forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m Natural lengthTBQueue isEmptyTBQueue :: forall a. TBQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) Bool isEmptyTBQueue = STM m Bool -> WithEarlyExit (STM m) Bool forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m Bool -> WithEarlyExit (STM m) Bool) -> (TBQueue m a -> STM m Bool) -> TBQueue m a -> WithEarlyExit (STM m) Bool forall b c a. (b -> c) -> (a -> b) -> a -> c . TBQueue m a -> STM m Bool forall a. TBQueue m a -> STM m Bool forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m Bool isEmptyTBQueue isFullTBQueue :: forall a. TBQueue (WithEarlyExit m) a -> STM (WithEarlyExit m) Bool isFullTBQueue = STM m Bool -> WithEarlyExit (STM m) Bool forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m Bool -> WithEarlyExit (STM m) Bool) -> (TBQueue m a -> STM m Bool) -> TBQueue m a -> WithEarlyExit (STM m) Bool forall b c a. (b -> c) -> (a -> b) -> a -> c . TBQueue m a -> STM m Bool forall a. TBQueue m a -> STM m Bool forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> STM m Bool isFullTBQueue unGetTBQueue :: forall a. TBQueue (WithEarlyExit m) a -> a -> STM (WithEarlyExit m) () unGetTBQueue = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TBQueue m a -> a -> STM m ()) -> TBQueue m a -> a -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TBQueue m a -> a -> STM m () forall a. TBQueue m a -> a -> STM m () forall (m :: * -> *) a. MonadSTM m => TBQueue m a -> a -> STM m () unGetTBQueue newTSem :: Integer -> STM (WithEarlyExit m) (TSem (WithEarlyExit m)) newTSem = STM m (TSem m) -> WithEarlyExit (STM m) (TSem m) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (TSem m) -> WithEarlyExit (STM m) (TSem m)) -> (Integer -> STM m (TSem m)) -> Integer -> WithEarlyExit (STM m) (TSem m) forall b c a. (b -> c) -> (a -> b) -> a -> c . Integer -> STM m (TSem m) forall (m :: * -> *). MonadSTM m => Integer -> STM m (TSem m) newTSem waitTSem :: TSem (WithEarlyExit m) -> STM (WithEarlyExit m) () waitTSem = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TSem m -> STM m ()) -> TSem m -> WithEarlyExit (STM m) () forall b c a. (b -> c) -> (a -> b) -> a -> c . TSem m -> STM m () forall (m :: * -> *). MonadSTM m => TSem m -> STM m () waitTSem signalTSem :: TSem (WithEarlyExit m) -> STM (WithEarlyExit m) () signalTSem = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TSem m -> STM m ()) -> TSem m -> WithEarlyExit (STM m) () forall b c a. (b -> c) -> (a -> b) -> a -> c . TSem m -> STM m () forall (m :: * -> *). MonadSTM m => TSem m -> STM m () signalTSem signalTSemN :: Natural -> TSem (WithEarlyExit m) -> STM (WithEarlyExit m) () signalTSemN = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (Natural -> TSem m -> STM m ()) -> Natural -> TSem m -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: Natural -> TSem m -> STM m () forall (m :: * -> *). MonadSTM m => Natural -> TSem m -> STM m () signalTSemN newTChan :: forall a. STM (WithEarlyExit m) (TChan (WithEarlyExit m) a) newTChan = STM m (TChan m a) -> WithEarlyExit (STM m) (TChan m a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift STM m (TChan m a) forall a. STM m (TChan m a) forall (m :: * -> *) a. MonadSTM m => STM m (TChan m a) newTChan newBroadcastTChan :: forall a. STM (WithEarlyExit m) (TChan (WithEarlyExit m) a) newBroadcastTChan = STM m (TChan m a) -> WithEarlyExit (STM m) (TChan m a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift STM m (TChan m a) forall a. STM m (TChan m a) forall (m :: * -> *) a. MonadSTM m => STM m (TChan m a) newBroadcastTChan dupTChan :: forall a. TChan (WithEarlyExit m) a -> STM (WithEarlyExit m) (TChan (WithEarlyExit m) a) dupTChan = STM m (TChan m a) -> WithEarlyExit (STM m) (TChan m a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (TChan m a) -> WithEarlyExit (STM m) (TChan m a)) -> (TChan m a -> STM m (TChan m a)) -> TChan m a -> WithEarlyExit (STM m) (TChan m a) forall b c a. (b -> c) -> (a -> b) -> a -> c . TChan m a -> STM m (TChan m a) forall a. TChan m a -> STM m (TChan m a) forall (m :: * -> *) a. MonadSTM m => TChan m a -> STM m (TChan m a) dupTChan cloneTChan :: forall a. TChan (WithEarlyExit m) a -> STM (WithEarlyExit m) (TChan (WithEarlyExit m) a) cloneTChan = STM m (TChan m a) -> WithEarlyExit (STM m) (TChan m a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (TChan m a) -> WithEarlyExit (STM m) (TChan m a)) -> (TChan m a -> STM m (TChan m a)) -> TChan m a -> WithEarlyExit (STM m) (TChan m a) forall b c a. (b -> c) -> (a -> b) -> a -> c . TChan m a -> STM m (TChan m a) forall a. TChan m a -> STM m (TChan m a) forall (m :: * -> *) a. MonadSTM m => TChan m a -> STM m (TChan m a) cloneTChan readTChan :: forall a. TChan (WithEarlyExit m) a -> STM (WithEarlyExit m) a readTChan = STM m a -> WithEarlyExit (STM m) a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m a -> WithEarlyExit (STM m) a) -> (TChan m a -> STM m a) -> TChan m a -> WithEarlyExit (STM m) a forall b c a. (b -> c) -> (a -> b) -> a -> c . TChan m a -> STM m a forall a. TChan m a -> STM m a forall (m :: * -> *) a. MonadSTM m => TChan m a -> STM m a readTChan tryReadTChan :: forall a. TChan (WithEarlyExit m) a -> STM (WithEarlyExit m) (Maybe a) tryReadTChan = STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a)) -> (TChan m a -> STM m (Maybe a)) -> TChan m a -> WithEarlyExit (STM m) (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . TChan m a -> STM m (Maybe a) forall a. TChan m a -> STM m (Maybe a) forall (m :: * -> *) a. MonadSTM m => TChan m a -> STM m (Maybe a) tryReadTChan peekTChan :: forall a. TChan (WithEarlyExit m) a -> STM (WithEarlyExit m) a peekTChan = STM m a -> WithEarlyExit (STM m) a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m a -> WithEarlyExit (STM m) a) -> (TChan m a -> STM m a) -> TChan m a -> WithEarlyExit (STM m) a forall b c a. (b -> c) -> (a -> b) -> a -> c . TChan m a -> STM m a forall a. TChan m a -> STM m a forall (m :: * -> *) a. MonadSTM m => TChan m a -> STM m a peekTChan tryPeekTChan :: forall a. TChan (WithEarlyExit m) a -> STM (WithEarlyExit m) (Maybe a) tryPeekTChan = STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m (Maybe a) -> WithEarlyExit (STM m) (Maybe a)) -> (TChan m a -> STM m (Maybe a)) -> TChan m a -> WithEarlyExit (STM m) (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . TChan m a -> STM m (Maybe a) forall a. TChan m a -> STM m (Maybe a) forall (m :: * -> *) a. MonadSTM m => TChan m a -> STM m (Maybe a) tryPeekTChan writeTChan :: forall a. TChan (WithEarlyExit m) a -> a -> STM (WithEarlyExit m) () writeTChan = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TChan m a -> a -> STM m ()) -> TChan m a -> a -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TChan m a -> a -> STM m () forall a. TChan m a -> a -> STM m () forall (m :: * -> *) a. MonadSTM m => TChan m a -> a -> STM m () writeTChan unGetTChan :: forall a. TChan (WithEarlyExit m) a -> a -> STM (WithEarlyExit m) () unGetTChan = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TChan m a -> a -> STM m ()) -> TChan m a -> a -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TChan m a -> a -> STM m () forall a. TChan m a -> a -> STM m () forall (m :: * -> *) a. MonadSTM m => TChan m a -> a -> STM m () unGetTChan isEmptyTChan :: forall a. TChan (WithEarlyExit m) a -> STM (WithEarlyExit m) Bool isEmptyTChan = STM m Bool -> WithEarlyExit (STM m) Bool forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m Bool -> WithEarlyExit (STM m) Bool) -> (TChan m a -> STM m Bool) -> TChan m a -> WithEarlyExit (STM m) Bool forall b c a. (b -> c) -> (a -> b) -> a -> c . TChan m a -> STM m Bool forall a. TChan m a -> STM m Bool forall (m :: * -> *) a. MonadSTM m => TChan m a -> STM m Bool isEmptyTChan newTMVarIO :: forall a. a -> WithEarlyExit m (TMVar (WithEarlyExit m) a) newTMVarIO = m (TMVar m a) -> WithEarlyExit m (TMVar m a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m (TMVar m a) -> WithEarlyExit m (TMVar m a)) -> (a -> m (TMVar m a)) -> a -> WithEarlyExit m (TMVar m a) forall b c a. (b -> c) -> (a -> b) -> a -> c . a -> m (TMVar m a) forall a. a -> m (TMVar m a) forall (m :: * -> *) a. MonadSTM m => a -> m (TMVar m a) newTMVarIO newEmptyTMVarIO :: forall a. WithEarlyExit m (TMVar (WithEarlyExit m) a) newEmptyTMVarIO = m (TMVar m a) -> WithEarlyExit m (TMVar m a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift m (TMVar m a) forall a. m (TMVar m a) forall (m :: * -> *) a. MonadSTM m => m (TMVar m a) newEmptyTMVarIO instance (MonadMVar m, MonadMask m, MonadEvaluate m) => MonadMVar (WithEarlyExit m) where type MVar (WithEarlyExit m) = MVar m newEmptyMVar :: forall a. WithEarlyExit m (MVar (WithEarlyExit m) a) newEmptyMVar = m (MVar m a) -> WithEarlyExit m (MVar m a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift m (MVar m a) forall a. m (MVar m a) forall (m :: * -> *) a. MonadMVar m => m (MVar m a) newEmptyMVar takeMVar :: forall a. MVar (WithEarlyExit m) a -> WithEarlyExit m a takeMVar = m a -> WithEarlyExit m a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m a -> WithEarlyExit m a) -> (MVar m a -> m a) -> MVar m a -> WithEarlyExit m a forall b c a. (b -> c) -> (a -> b) -> a -> c . MVar m a -> m a forall a. MVar m a -> m a forall (m :: * -> *) a. MonadMVar m => MVar m a -> m a takeMVar putMVar :: forall a. MVar (WithEarlyExit m) a -> a -> WithEarlyExit m () putMVar = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (MVar m a -> a -> m ()) -> MVar m a -> a -> WithEarlyExit m () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: MVar m a -> a -> m () forall a. MVar m a -> a -> m () forall (m :: * -> *) a. MonadMVar m => MVar m a -> a -> m () putMVar tryTakeMVar :: forall a. MVar (WithEarlyExit m) a -> WithEarlyExit m (Maybe a) tryTakeMVar = m (Maybe a) -> WithEarlyExit m (Maybe a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m (Maybe a) -> WithEarlyExit m (Maybe a)) -> (MVar m a -> m (Maybe a)) -> MVar m a -> WithEarlyExit m (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . MVar m a -> m (Maybe a) forall a. MVar m a -> m (Maybe a) forall (m :: * -> *) a. MonadMVar m => MVar m a -> m (Maybe a) tryTakeMVar tryPutMVar :: forall a. MVar (WithEarlyExit m) a -> a -> WithEarlyExit m Bool tryPutMVar = m Bool -> WithEarlyExit m Bool forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m Bool -> WithEarlyExit m Bool) -> (MVar m a -> a -> m Bool) -> MVar m a -> a -> WithEarlyExit m Bool forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: MVar m a -> a -> m Bool forall a. MVar m a -> a -> m Bool forall (m :: * -> *) a. MonadMVar m => MVar m a -> a -> m Bool tryPutMVar tryReadMVar :: forall a. MVar (WithEarlyExit m) a -> WithEarlyExit m (Maybe a) tryReadMVar = m (Maybe a) -> WithEarlyExit m (Maybe a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m (Maybe a) -> WithEarlyExit m (Maybe a)) -> (MVar m a -> m (Maybe a)) -> MVar m a -> WithEarlyExit m (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . MVar m a -> m (Maybe a) forall a. MVar m a -> m (Maybe a) forall (m :: * -> *) a. MonadMVar m => MVar m a -> m (Maybe a) tryReadMVar isEmptyMVar :: forall a. MVar (WithEarlyExit m) a -> WithEarlyExit m Bool isEmptyMVar = m Bool -> WithEarlyExit m Bool forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m Bool -> WithEarlyExit m Bool) -> (MVar m a -> m Bool) -> MVar m a -> WithEarlyExit m Bool forall b c a. (b -> c) -> (a -> b) -> a -> c . MVar m a -> m Bool forall a. MVar m a -> m Bool forall (m :: * -> *) a. MonadMVar m => MVar m a -> m Bool isEmptyMVar newMVar :: forall a. a -> WithEarlyExit m (MVar (WithEarlyExit m) a) newMVar = m (MVar m a) -> WithEarlyExit m (MVar m a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m (MVar m a) -> WithEarlyExit m (MVar m a)) -> (a -> m (MVar m a)) -> a -> WithEarlyExit m (MVar m a) forall b c a. (b -> c) -> (a -> b) -> a -> c . a -> m (MVar m a) forall a. a -> m (MVar m a) forall (m :: * -> *) a. MonadMVar m => a -> m (MVar m a) newMVar readMVar :: forall a. MVar (WithEarlyExit m) a -> WithEarlyExit m a readMVar = m a -> WithEarlyExit m a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m a -> WithEarlyExit m a) -> (MVar m a -> m a) -> MVar m a -> WithEarlyExit m a forall b c a. (b -> c) -> (a -> b) -> a -> c . MVar m a -> m a forall a. MVar m a -> m a forall (m :: * -> *) a. MonadMVar m => MVar m a -> m a readMVar swapMVar :: forall a. MVar (WithEarlyExit m) a -> a -> WithEarlyExit m a swapMVar = m a -> WithEarlyExit m a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m a -> WithEarlyExit m a) -> (MVar m a -> a -> m a) -> MVar m a -> a -> WithEarlyExit m a forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: MVar m a -> a -> m a forall a. MVar m a -> a -> m a forall (m :: * -> *) a. MonadMVar m => MVar m a -> a -> m a swapMVar instance MonadCatch m => MonadThrow (WithEarlyExit m) where throwIO :: forall e a. Exception e => e -> WithEarlyExit m a throwIO = m a -> WithEarlyExit m a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m a -> WithEarlyExit m a) -> (e -> m a) -> e -> WithEarlyExit m a forall b c a. (b -> c) -> (a -> b) -> a -> c . e -> m a forall e a. Exception e => e -> m a forall (m :: * -> *) e a. (MonadThrow m, Exception e) => e -> m a throwIO #if __GLASGOW_HASKELL__ >= 910 -- This method is defined in the io-classes package (part of the io-sim repository) where -- it is guarded by the GHC version as above. annotateIO = annotateIO #endif instance MonadCatch m => MonadCatch (WithEarlyExit m) where catch :: forall e a. Exception e => WithEarlyExit m a -> (e -> WithEarlyExit m a) -> WithEarlyExit m a catch WithEarlyExit m a act e -> WithEarlyExit m a handler = m (Maybe a) -> WithEarlyExit m a forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Maybe a) -> WithEarlyExit m a) -> m (Maybe a) -> WithEarlyExit m a forall a b. (a -> b) -> a -> b $ m (Maybe a) -> (e -> m (Maybe a)) -> m (Maybe a) forall e a. Exception e => m a -> (e -> m a) -> m a forall (m :: * -> *) e a. (MonadCatch m, Exception e) => m a -> (e -> m a) -> m a catch (WithEarlyExit m a -> m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit WithEarlyExit m a act) (WithEarlyExit m a -> m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit (WithEarlyExit m a -> m (Maybe a)) -> (e -> WithEarlyExit m a) -> e -> m (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . e -> WithEarlyExit m a handler) generalBracket :: forall a b c. WithEarlyExit m a -> (a -> ExitCase b -> WithEarlyExit m c) -> (a -> WithEarlyExit m b) -> WithEarlyExit m (b, c) generalBracket WithEarlyExit m a acquire a -> ExitCase b -> WithEarlyExit m c release a -> WithEarlyExit m b use = m (Maybe (b, c)) -> WithEarlyExit m (b, c) forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Maybe (b, c)) -> WithEarlyExit m (b, c)) -> m (Maybe (b, c)) -> WithEarlyExit m (b, c) forall a b. (a -> b) -> a -> b $ do -- This is modelled on the case for ErrorT, except that we don't have -- to worry about reporting the right error, since we only have @Nothing@ (Maybe b mb, Maybe c mc) <- m (Maybe a) -> (Maybe a -> ExitCase (Maybe b) -> m (Maybe c)) -> (Maybe a -> m (Maybe b)) -> m (Maybe b, Maybe c) forall a b c. m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c) forall (m :: * -> *) a b c. MonadCatch m => m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c) generalBracket (WithEarlyExit m a -> m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit WithEarlyExit m a acquire) (\Maybe a mResource ExitCase (Maybe b) exitCase -> case (Maybe a mResource, ExitCase (Maybe b) exitCase) of (Maybe a Nothing, ExitCase (Maybe b) _) -> -- resource not acquired Maybe c -> m (Maybe c) forall a. a -> m a forall (m :: * -> *) a. Monad m => a -> m a return Maybe c forall a. Maybe a Nothing (Just a resource, ExitCaseSuccess (Just b b)) -> WithEarlyExit m c -> m (Maybe c) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit (WithEarlyExit m c -> m (Maybe c)) -> WithEarlyExit m c -> m (Maybe c) forall a b. (a -> b) -> a -> b $ a -> ExitCase b -> WithEarlyExit m c release a resource (b -> ExitCase b forall a. a -> ExitCase a ExitCaseSuccess b b) (Just a resource, ExitCaseException SomeException e) -> WithEarlyExit m c -> m (Maybe c) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit (WithEarlyExit m c -> m (Maybe c)) -> WithEarlyExit m c -> m (Maybe c) forall a b. (a -> b) -> a -> b $ a -> ExitCase b -> WithEarlyExit m c release a resource (SomeException -> ExitCase b forall a. SomeException -> ExitCase a ExitCaseException SomeException e) (Just a resource, ExitCase (Maybe b) _otherwise) -> WithEarlyExit m c -> m (Maybe c) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit (WithEarlyExit m c -> m (Maybe c)) -> WithEarlyExit m c -> m (Maybe c) forall a b. (a -> b) -> a -> b $ a -> ExitCase b -> WithEarlyExit m c release a resource ExitCase b forall a. ExitCase a ExitCaseAbort ) (m (Maybe b) -> (a -> m (Maybe b)) -> Maybe a -> m (Maybe b) forall b a. b -> (a -> b) -> Maybe a -> b maybe (Maybe b -> m (Maybe b) forall a. a -> m a forall (m :: * -> *) a. Monad m => a -> m a return Maybe b forall a. Maybe a Nothing) (WithEarlyExit m b -> m (Maybe b) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit (WithEarlyExit m b -> m (Maybe b)) -> (a -> WithEarlyExit m b) -> a -> m (Maybe b) forall b c a. (b -> c) -> (a -> b) -> a -> c . a -> WithEarlyExit m b use)) Maybe (b, c) -> m (Maybe (b, c)) forall a. a -> m a forall (m :: * -> *) a. Monad m => a -> m a return (Maybe (b, c) -> m (Maybe (b, c))) -> Maybe (b, c) -> m (Maybe (b, c)) forall a b. (a -> b) -> a -> b $ (,) (b -> c -> (b, c)) -> Maybe b -> Maybe (c -> (b, c)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Maybe b mb Maybe (c -> (b, c)) -> Maybe c -> Maybe (b, c) forall a b. Maybe (a -> b) -> Maybe a -> Maybe b forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Maybe c mc instance MonadMask m => MonadMask (WithEarlyExit m) where mask :: forall b. ((forall a. WithEarlyExit m a -> WithEarlyExit m a) -> WithEarlyExit m b) -> WithEarlyExit m b mask (forall a. WithEarlyExit m a -> WithEarlyExit m a) -> WithEarlyExit m b f = m (Maybe b) -> WithEarlyExit m b forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Maybe b) -> WithEarlyExit m b) -> m (Maybe b) -> WithEarlyExit m b forall a b. (a -> b) -> a -> b $ ((forall a. m a -> m a) -> m (Maybe b)) -> m (Maybe b) forall b. ((forall a. m a -> m a) -> m b) -> m b forall (m :: * -> *) b. MonadMask m => ((forall a. m a -> m a) -> m b) -> m b mask (((forall a. m a -> m a) -> m (Maybe b)) -> m (Maybe b)) -> ((forall a. m a -> m a) -> m (Maybe b)) -> m (Maybe b) forall a b. (a -> b) -> a -> b $ \forall a. m a -> m a unmask -> WithEarlyExit m b -> m (Maybe b) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit ((forall a. WithEarlyExit m a -> WithEarlyExit m a) -> WithEarlyExit m b f (m (Maybe a) -> WithEarlyExit m a forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Maybe a) -> WithEarlyExit m a) -> (WithEarlyExit m a -> m (Maybe a)) -> WithEarlyExit m a -> WithEarlyExit m a forall b c a. (b -> c) -> (a -> b) -> a -> c . m (Maybe a) -> m (Maybe a) forall a. m a -> m a unmask (m (Maybe a) -> m (Maybe a)) -> (WithEarlyExit m a -> m (Maybe a)) -> WithEarlyExit m a -> m (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . WithEarlyExit m a -> m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit)) uninterruptibleMask :: forall b. ((forall a. WithEarlyExit m a -> WithEarlyExit m a) -> WithEarlyExit m b) -> WithEarlyExit m b uninterruptibleMask (forall a. WithEarlyExit m a -> WithEarlyExit m a) -> WithEarlyExit m b f = m (Maybe b) -> WithEarlyExit m b forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Maybe b) -> WithEarlyExit m b) -> m (Maybe b) -> WithEarlyExit m b forall a b. (a -> b) -> a -> b $ ((forall a. m a -> m a) -> m (Maybe b)) -> m (Maybe b) forall b. ((forall a. m a -> m a) -> m b) -> m b forall (m :: * -> *) b. MonadMask m => ((forall a. m a -> m a) -> m b) -> m b uninterruptibleMask (((forall a. m a -> m a) -> m (Maybe b)) -> m (Maybe b)) -> ((forall a. m a -> m a) -> m (Maybe b)) -> m (Maybe b) forall a b. (a -> b) -> a -> b $ \forall a. m a -> m a unmask -> let unmask' :: forall a. WithEarlyExit m a -> WithEarlyExit m a unmask' :: forall a. WithEarlyExit m a -> WithEarlyExit m a unmask' = m (Maybe a) -> WithEarlyExit m a forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Maybe a) -> WithEarlyExit m a) -> (WithEarlyExit m a -> m (Maybe a)) -> WithEarlyExit m a -> WithEarlyExit m a forall b c a. (b -> c) -> (a -> b) -> a -> c . m (Maybe a) -> m (Maybe a) forall a. m a -> m a unmask (m (Maybe a) -> m (Maybe a)) -> (WithEarlyExit m a -> m (Maybe a)) -> WithEarlyExit m a -> m (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . WithEarlyExit m a -> m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit in WithEarlyExit m b -> m (Maybe b) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit ((forall a. WithEarlyExit m a -> WithEarlyExit m a) -> WithEarlyExit m b f WithEarlyExit m a -> WithEarlyExit m a forall a. WithEarlyExit m a -> WithEarlyExit m a unmask') instance MonadThread m => MonadThread (WithEarlyExit m) where type ThreadId (WithEarlyExit m) = ThreadId m myThreadId :: WithEarlyExit m (ThreadId (WithEarlyExit m)) myThreadId = m (ThreadId m) -> WithEarlyExit m (ThreadId m) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift m (ThreadId m) forall (m :: * -> *). MonadThread m => m (ThreadId m) myThreadId labelThread :: ThreadId (WithEarlyExit m) -> String -> WithEarlyExit m () labelThread = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (ThreadId m -> String -> m ()) -> ThreadId m -> String -> WithEarlyExit m () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: ThreadId m -> String -> m () forall (m :: * -> *). MonadThread m => ThreadId m -> String -> m () labelThread instance (MonadMask m, MonadAsync m, MonadCatch (STM m)) => MonadAsync (WithEarlyExit m) where type Async (WithEarlyExit m) = WithEarlyExit (Async m) async :: forall a. WithEarlyExit m a -> WithEarlyExit m (Async (WithEarlyExit m) a) async = m (WithEarlyExit (Async m) a) -> WithEarlyExit m (WithEarlyExit (Async m) a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m (WithEarlyExit (Async m) a) -> WithEarlyExit m (WithEarlyExit (Async m) a)) -> (WithEarlyExit m a -> m (WithEarlyExit (Async m) a)) -> WithEarlyExit m a -> WithEarlyExit m (WithEarlyExit (Async m) a) forall b c a. (b -> c) -> (a -> b) -> a -> c . ((Async m (Maybe a) -> WithEarlyExit (Async m) a) -> m (Async m (Maybe a)) -> m (WithEarlyExit (Async m) a) forall a b. (a -> b) -> m a -> m b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Async m (Maybe a) -> WithEarlyExit (Async m) a forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Async m (Maybe a)) -> m (WithEarlyExit (Async m) a)) -> (m (Maybe a) -> m (Async m (Maybe a))) -> m (Maybe a) -> m (WithEarlyExit (Async m) a) forall b c a. (b -> c) -> (a -> b) -> a -> c . m (Maybe a) -> m (Async m (Maybe a)) forall a. m a -> m (Async m a) forall (m :: * -> *) a. MonadAsync m => m a -> m (Async m a) async) (m (Maybe a) -> m (WithEarlyExit (Async m) a)) -> (WithEarlyExit m a -> m (Maybe a)) -> WithEarlyExit m a -> m (WithEarlyExit (Async m) a) forall b c a. (b -> c) -> (a -> b) -> a -> c . WithEarlyExit m a -> m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit asyncBound :: forall a. WithEarlyExit m a -> WithEarlyExit m (Async (WithEarlyExit m) a) asyncBound = m (WithEarlyExit (Async m) a) -> WithEarlyExit m (WithEarlyExit (Async m) a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m (WithEarlyExit (Async m) a) -> WithEarlyExit m (WithEarlyExit (Async m) a)) -> (WithEarlyExit m a -> m (WithEarlyExit (Async m) a)) -> WithEarlyExit m a -> WithEarlyExit m (WithEarlyExit (Async m) a) forall b c a. (b -> c) -> (a -> b) -> a -> c . ((Async m (Maybe a) -> WithEarlyExit (Async m) a) -> m (Async m (Maybe a)) -> m (WithEarlyExit (Async m) a) forall a b. (a -> b) -> m a -> m b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Async m (Maybe a) -> WithEarlyExit (Async m) a forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Async m (Maybe a)) -> m (WithEarlyExit (Async m) a)) -> (m (Maybe a) -> m (Async m (Maybe a))) -> m (Maybe a) -> m (WithEarlyExit (Async m) a) forall b c a. (b -> c) -> (a -> b) -> a -> c . m (Maybe a) -> m (Async m (Maybe a)) forall a. m a -> m (Async m a) forall (m :: * -> *) a. MonadAsync m => m a -> m (Async m a) async) (m (Maybe a) -> m (WithEarlyExit (Async m) a)) -> (WithEarlyExit m a -> m (Maybe a)) -> WithEarlyExit m a -> m (WithEarlyExit (Async m) a) forall b c a. (b -> c) -> (a -> b) -> a -> c . WithEarlyExit m a -> m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit asyncOn :: forall a. Int -> WithEarlyExit m a -> WithEarlyExit m (Async (WithEarlyExit m) a) asyncOn Int n = m (WithEarlyExit (Async m) a) -> WithEarlyExit m (WithEarlyExit (Async m) a) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m (WithEarlyExit (Async m) a) -> WithEarlyExit m (WithEarlyExit (Async m) a)) -> (WithEarlyExit m a -> m (WithEarlyExit (Async m) a)) -> WithEarlyExit m a -> WithEarlyExit m (WithEarlyExit (Async m) a) forall b c a. (b -> c) -> (a -> b) -> a -> c . ((Async m (Maybe a) -> WithEarlyExit (Async m) a) -> m (Async m (Maybe a)) -> m (WithEarlyExit (Async m) a) forall a b. (a -> b) -> m a -> m b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Async m (Maybe a) -> WithEarlyExit (Async m) a forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Async m (Maybe a)) -> m (WithEarlyExit (Async m) a)) -> (m (Maybe a) -> m (Async m (Maybe a))) -> m (Maybe a) -> m (WithEarlyExit (Async m) a) forall b c a. (b -> c) -> (a -> b) -> a -> c . Int -> m (Maybe a) -> m (Async m (Maybe a)) forall a. Int -> m a -> m (Async m a) forall (m :: * -> *) a. MonadAsync m => Int -> m a -> m (Async m a) asyncOn Int n) (m (Maybe a) -> m (WithEarlyExit (Async m) a)) -> (WithEarlyExit m a -> m (Maybe a)) -> WithEarlyExit m a -> m (WithEarlyExit (Async m) a) forall b c a. (b -> c) -> (a -> b) -> a -> c . WithEarlyExit m a -> m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit asyncThreadId :: forall a. Async (WithEarlyExit m) a -> ThreadId (WithEarlyExit m) asyncThreadId = Async (WithEarlyExit m) a -> ThreadId (WithEarlyExit m) forall a. Async (WithEarlyExit m) a -> ThreadId (WithEarlyExit m) forall (m :: * -> *) a. MonadAsync m => Async m a -> ThreadId m asyncThreadId cancel :: forall a. Async (WithEarlyExit m) a -> WithEarlyExit m () cancel Async (WithEarlyExit m) a a = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> m () -> WithEarlyExit m () forall a b. (a -> b) -> a -> b $ Async m (Maybe a) -> m () forall a. Async m a -> m () forall (m :: * -> *) a. MonadAsync m => Async m a -> m () cancel (WithEarlyExit (Async m) a -> Async m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit Async (WithEarlyExit m) a WithEarlyExit (Async m) a a) cancelWith :: forall e a. Exception e => Async (WithEarlyExit m) a -> e -> WithEarlyExit m () cancelWith Async (WithEarlyExit m) a a = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (e -> m ()) -> e -> WithEarlyExit m () forall b c a. (b -> c) -> (a -> b) -> a -> c . Async m (Maybe a) -> e -> m () forall e a. Exception e => Async m a -> e -> m () forall (m :: * -> *) e a. (MonadAsync m, Exception e) => Async m a -> e -> m () cancelWith (WithEarlyExit (Async m) a -> Async m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit Async (WithEarlyExit m) a WithEarlyExit (Async m) a a) waitCatchSTM :: forall a. Async (WithEarlyExit m) a -> STM (WithEarlyExit m) (Either SomeException a) waitCatchSTM Async (WithEarlyExit m) a a = STM m (Maybe (Either SomeException a)) -> WithEarlyExit (STM m) (Either SomeException a) forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (Either SomeException (Maybe a) -> Maybe (Either SomeException a) forall a. Either SomeException (Maybe a) -> Maybe (Either SomeException a) commute (Either SomeException (Maybe a) -> Maybe (Either SomeException a)) -> STM m (Either SomeException (Maybe a)) -> STM m (Maybe (Either SomeException a)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Async m (Maybe a) -> STM m (Either SomeException (Maybe a)) forall a. Async m a -> STM m (Either SomeException a) forall (m :: * -> *) a. MonadAsync m => Async m a -> STM m (Either SomeException a) waitCatchSTM (WithEarlyExit (Async m) a -> Async m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit Async (WithEarlyExit m) a WithEarlyExit (Async m) a a)) pollSTM :: forall a. Async (WithEarlyExit m) a -> STM (WithEarlyExit m) (Maybe (Either SomeException a)) pollSTM Async (WithEarlyExit m) a a = STM m (Maybe (Maybe (Either SomeException a))) -> WithEarlyExit (STM m) (Maybe (Either SomeException a)) forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit ((Either SomeException (Maybe a) -> Maybe (Either SomeException a)) -> Maybe (Either SomeException (Maybe a)) -> Maybe (Maybe (Either SomeException a)) forall a b. (a -> b) -> Maybe a -> Maybe b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap Either SomeException (Maybe a) -> Maybe (Either SomeException a) forall a. Either SomeException (Maybe a) -> Maybe (Either SomeException a) commute (Maybe (Either SomeException (Maybe a)) -> Maybe (Maybe (Either SomeException a))) -> STM m (Maybe (Either SomeException (Maybe a))) -> STM m (Maybe (Maybe (Either SomeException a))) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> Async m (Maybe a) -> STM m (Maybe (Either SomeException (Maybe a))) forall a. Async m a -> STM m (Maybe (Either SomeException a)) forall (m :: * -> *) a. MonadAsync m => Async m a -> STM m (Maybe (Either SomeException a)) pollSTM (WithEarlyExit (Async m) a -> Async m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit Async (WithEarlyExit m) a WithEarlyExit (Async m) a a)) asyncWithUnmask :: forall a. ((forall b. WithEarlyExit m b -> WithEarlyExit m b) -> WithEarlyExit m a) -> WithEarlyExit m (Async (WithEarlyExit m) a) asyncWithUnmask (forall b. WithEarlyExit m b -> WithEarlyExit m b) -> WithEarlyExit m a f = m (Maybe (Async (WithEarlyExit m) a)) -> WithEarlyExit m (Async (WithEarlyExit m) a) forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Maybe (Async (WithEarlyExit m) a)) -> WithEarlyExit m (Async (WithEarlyExit m) a)) -> m (Maybe (Async (WithEarlyExit m) a)) -> WithEarlyExit m (Async (WithEarlyExit m) a) forall a b. (a -> b) -> a -> b $ (Async m (Maybe a) -> Maybe (Async (WithEarlyExit m) a)) -> m (Async m (Maybe a)) -> m (Maybe (Async (WithEarlyExit m) a)) forall a b. (a -> b) -> m a -> m b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap (WithEarlyExit (Async m) a -> Maybe (WithEarlyExit (Async m) a) forall a. a -> Maybe a Just (WithEarlyExit (Async m) a -> Maybe (WithEarlyExit (Async m) a)) -> (Async m (Maybe a) -> WithEarlyExit (Async m) a) -> Async m (Maybe a) -> Maybe (WithEarlyExit (Async m) a) forall b c a. (b -> c) -> (a -> b) -> a -> c . Async m (Maybe a) -> WithEarlyExit (Async m) a forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit) (m (Async m (Maybe a)) -> m (Maybe (Async (WithEarlyExit m) a))) -> m (Async m (Maybe a)) -> m (Maybe (Async (WithEarlyExit m) a)) forall a b. (a -> b) -> a -> b $ ((forall b. m b -> m b) -> m (Maybe a)) -> m (Async m (Maybe a)) forall a. ((forall b. m b -> m b) -> m a) -> m (Async m a) forall (m :: * -> *) a. MonadAsync m => ((forall b. m b -> m b) -> m a) -> m (Async m a) asyncWithUnmask (((forall b. m b -> m b) -> m (Maybe a)) -> m (Async m (Maybe a))) -> ((forall b. m b -> m b) -> m (Maybe a)) -> m (Async m (Maybe a)) forall a b. (a -> b) -> a -> b $ \forall b. m b -> m b unmask -> WithEarlyExit m a -> m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit ((forall b. WithEarlyExit m b -> WithEarlyExit m b) -> WithEarlyExit m a f (m (Maybe b) -> WithEarlyExit m b forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Maybe b) -> WithEarlyExit m b) -> (WithEarlyExit m b -> m (Maybe b)) -> WithEarlyExit m b -> WithEarlyExit m b forall b c a. (b -> c) -> (a -> b) -> a -> c . m (Maybe b) -> m (Maybe b) forall b. m b -> m b unmask (m (Maybe b) -> m (Maybe b)) -> (WithEarlyExit m b -> m (Maybe b)) -> WithEarlyExit m b -> m (Maybe b) forall b c a. (b -> c) -> (a -> b) -> a -> c . WithEarlyExit m b -> m (Maybe b) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit)) asyncOnWithUnmask :: forall a. Int -> ((forall b. WithEarlyExit m b -> WithEarlyExit m b) -> WithEarlyExit m a) -> WithEarlyExit m (Async (WithEarlyExit m) a) asyncOnWithUnmask Int n (forall b. WithEarlyExit m b -> WithEarlyExit m b) -> WithEarlyExit m a f = m (Maybe (Async (WithEarlyExit m) a)) -> WithEarlyExit m (Async (WithEarlyExit m) a) forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Maybe (Async (WithEarlyExit m) a)) -> WithEarlyExit m (Async (WithEarlyExit m) a)) -> m (Maybe (Async (WithEarlyExit m) a)) -> WithEarlyExit m (Async (WithEarlyExit m) a) forall a b. (a -> b) -> a -> b $ (Async m (Maybe a) -> Maybe (Async (WithEarlyExit m) a)) -> m (Async m (Maybe a)) -> m (Maybe (Async (WithEarlyExit m) a)) forall a b. (a -> b) -> m a -> m b forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap (WithEarlyExit (Async m) a -> Maybe (WithEarlyExit (Async m) a) forall a. a -> Maybe a Just (WithEarlyExit (Async m) a -> Maybe (WithEarlyExit (Async m) a)) -> (Async m (Maybe a) -> WithEarlyExit (Async m) a) -> Async m (Maybe a) -> Maybe (WithEarlyExit (Async m) a) forall b c a. (b -> c) -> (a -> b) -> a -> c . Async m (Maybe a) -> WithEarlyExit (Async m) a forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit) (m (Async m (Maybe a)) -> m (Maybe (Async (WithEarlyExit m) a))) -> m (Async m (Maybe a)) -> m (Maybe (Async (WithEarlyExit m) a)) forall a b. (a -> b) -> a -> b $ Int -> ((forall b. m b -> m b) -> m (Maybe a)) -> m (Async m (Maybe a)) forall a. Int -> ((forall b. m b -> m b) -> m a) -> m (Async m a) forall (m :: * -> *) a. MonadAsync m => Int -> ((forall b. m b -> m b) -> m a) -> m (Async m a) asyncOnWithUnmask Int n (((forall b. m b -> m b) -> m (Maybe a)) -> m (Async m (Maybe a))) -> ((forall b. m b -> m b) -> m (Maybe a)) -> m (Async m (Maybe a)) forall a b. (a -> b) -> a -> b $ \forall b. m b -> m b unmask -> WithEarlyExit m a -> m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit ((forall b. WithEarlyExit m b -> WithEarlyExit m b) -> WithEarlyExit m a f (m (Maybe b) -> WithEarlyExit m b forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Maybe b) -> WithEarlyExit m b) -> (WithEarlyExit m b -> m (Maybe b)) -> WithEarlyExit m b -> WithEarlyExit m b forall b c a. (b -> c) -> (a -> b) -> a -> c . m (Maybe b) -> m (Maybe b) forall b. m b -> m b unmask (m (Maybe b) -> m (Maybe b)) -> (WithEarlyExit m b -> m (Maybe b)) -> WithEarlyExit m b -> m (Maybe b) forall b c a. (b -> c) -> (a -> b) -> a -> c . WithEarlyExit m b -> m (Maybe b) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit)) commute :: Either SomeException (Maybe a) -> Maybe (Either SomeException a) commute :: forall a. Either SomeException (Maybe a) -> Maybe (Either SomeException a) commute (Left SomeException e) = Either SomeException a -> Maybe (Either SomeException a) forall a. a -> Maybe a Just (SomeException -> Either SomeException a forall a b. a -> Either a b Left SomeException e) commute (Right Maybe a Nothing) = Maybe (Either SomeException a) forall a. Maybe a Nothing commute (Right (Just a a)) = Either SomeException a -> Maybe (Either SomeException a) forall a. a -> Maybe a Just (a -> Either SomeException a forall a b. b -> Either a b Right a a) instance MonadFork m => MonadFork (WithEarlyExit m) where forkIO :: WithEarlyExit m () -> WithEarlyExit m (ThreadId (WithEarlyExit m)) forkIO WithEarlyExit m () f = m (ThreadId (WithEarlyExit m)) -> WithEarlyExit m (ThreadId (WithEarlyExit m)) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m (ThreadId (WithEarlyExit m)) -> WithEarlyExit m (ThreadId (WithEarlyExit m))) -> m (ThreadId (WithEarlyExit m)) -> WithEarlyExit m (ThreadId (WithEarlyExit m)) forall a b. (a -> b) -> a -> b $ m () -> m (ThreadId m) forall (m :: * -> *). MonadFork m => m () -> m (ThreadId m) forkIO (Maybe () -> () collapse (Maybe () -> ()) -> m (Maybe ()) -> m () forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> WithEarlyExit m () -> m (Maybe ()) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit WithEarlyExit m () f) forkOn :: Int -> WithEarlyExit m () -> WithEarlyExit m (ThreadId (WithEarlyExit m)) forkOn Int n WithEarlyExit m () f = m (ThreadId (WithEarlyExit m)) -> WithEarlyExit m (ThreadId (WithEarlyExit m)) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m (ThreadId (WithEarlyExit m)) -> WithEarlyExit m (ThreadId (WithEarlyExit m))) -> m (ThreadId (WithEarlyExit m)) -> WithEarlyExit m (ThreadId (WithEarlyExit m)) forall a b. (a -> b) -> a -> b $ Int -> m () -> m (ThreadId m) forall (m :: * -> *). MonadFork m => Int -> m () -> m (ThreadId m) forkOn Int n (Maybe () -> () collapse (Maybe () -> ()) -> m (Maybe ()) -> m () forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> WithEarlyExit m () -> m (Maybe ()) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit WithEarlyExit m () f) forkIOWithUnmask :: ((forall a. WithEarlyExit m a -> WithEarlyExit m a) -> WithEarlyExit m ()) -> WithEarlyExit m (ThreadId (WithEarlyExit m)) forkIOWithUnmask (forall a. WithEarlyExit m a -> WithEarlyExit m a) -> WithEarlyExit m () f = m (ThreadId (WithEarlyExit m)) -> WithEarlyExit m (ThreadId (WithEarlyExit m)) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m (ThreadId (WithEarlyExit m)) -> WithEarlyExit m (ThreadId (WithEarlyExit m))) -> m (ThreadId (WithEarlyExit m)) -> WithEarlyExit m (ThreadId (WithEarlyExit m)) forall a b. (a -> b) -> a -> b $ ((forall a. m a -> m a) -> m ()) -> m (ThreadId m) forall (m :: * -> *). MonadFork m => ((forall a. m a -> m a) -> m ()) -> m (ThreadId m) forkIOWithUnmask (((forall a. m a -> m a) -> m ()) -> m (ThreadId m)) -> ((forall a. m a -> m a) -> m ()) -> m (ThreadId m) forall a b. (a -> b) -> a -> b $ \forall a. m a -> m a unmask -> let unmask' :: forall a. WithEarlyExit m a -> WithEarlyExit m a unmask' :: forall a. WithEarlyExit m a -> WithEarlyExit m a unmask' = m (Maybe a) -> WithEarlyExit m a forall (m :: * -> *) a. m (Maybe a) -> WithEarlyExit m a earlyExit (m (Maybe a) -> WithEarlyExit m a) -> (WithEarlyExit m a -> m (Maybe a)) -> WithEarlyExit m a -> WithEarlyExit m a forall b c a. (b -> c) -> (a -> b) -> a -> c . m (Maybe a) -> m (Maybe a) forall a. m a -> m a unmask (m (Maybe a) -> m (Maybe a)) -> (WithEarlyExit m a -> m (Maybe a)) -> WithEarlyExit m a -> m (Maybe a) forall b c a. (b -> c) -> (a -> b) -> a -> c . WithEarlyExit m a -> m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit in Maybe () -> () collapse (Maybe () -> ()) -> m (Maybe ()) -> m () forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> WithEarlyExit m () -> m (Maybe ()) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit ((forall a. WithEarlyExit m a -> WithEarlyExit m a) -> WithEarlyExit m () f WithEarlyExit m a -> WithEarlyExit m a forall a. WithEarlyExit m a -> WithEarlyExit m a unmask') forkFinally :: forall a. WithEarlyExit m a -> (Either SomeException a -> WithEarlyExit m ()) -> WithEarlyExit m (ThreadId (WithEarlyExit m)) forkFinally WithEarlyExit m a f Either SomeException a -> WithEarlyExit m () fin = m (ThreadId (WithEarlyExit m)) -> WithEarlyExit m (ThreadId (WithEarlyExit m)) forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m (ThreadId (WithEarlyExit m)) -> WithEarlyExit m (ThreadId (WithEarlyExit m))) -> m (ThreadId (WithEarlyExit m)) -> WithEarlyExit m (ThreadId (WithEarlyExit m)) forall a b. (a -> b) -> a -> b $ m (Maybe a) -> (Either SomeException (Maybe a) -> m ()) -> m (ThreadId m) forall a. m a -> (Either SomeException a -> m ()) -> m (ThreadId m) forall (m :: * -> *) a. MonadFork m => m a -> (Either SomeException a -> m ()) -> m (ThreadId m) forkFinally (WithEarlyExit m a -> m (Maybe a) forall (m :: * -> *) a. WithEarlyExit m a -> m (Maybe a) withEarlyExit WithEarlyExit m a f) (WithEarlyExit m () -> m () forall (m :: * -> *). Functor m => WithEarlyExit m () -> m () withEarlyExit_ (WithEarlyExit m () -> m ()) -> (Either SomeException (Maybe a) -> WithEarlyExit m ()) -> Either SomeException (Maybe a) -> m () forall b c a. (b -> c) -> (a -> b) -> a -> c . WithEarlyExit m () -> (Either SomeException a -> WithEarlyExit m ()) -> Maybe (Either SomeException a) -> WithEarlyExit m () forall b a. b -> (a -> b) -> Maybe a -> b maybe (() -> WithEarlyExit m () forall a. a -> WithEarlyExit m a forall (f :: * -> *) a. Applicative f => a -> f a pure ()) Either SomeException a -> WithEarlyExit m () fin (Maybe (Either SomeException a) -> WithEarlyExit m ()) -> (Either SomeException (Maybe a) -> Maybe (Either SomeException a)) -> Either SomeException (Maybe a) -> WithEarlyExit m () forall b c a. (b -> c) -> (a -> b) -> a -> c . Either SomeException (Maybe a) -> Maybe (Either SomeException a) forall a. Either SomeException (Maybe a) -> Maybe (Either SomeException a) commute) throwTo :: forall e. Exception e => ThreadId (WithEarlyExit m) -> e -> WithEarlyExit m () throwTo = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (ThreadId m -> e -> m ()) -> ThreadId m -> e -> WithEarlyExit m () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: ThreadId m -> e -> m () forall e. Exception e => ThreadId m -> e -> m () forall (m :: * -> *) e. (MonadFork m, Exception e) => ThreadId m -> e -> m () throwTo yield :: WithEarlyExit m () yield = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift m () forall (m :: * -> *). MonadFork m => m () yield instance PrimMonad m => PrimMonad (WithEarlyExit m) where type PrimState (WithEarlyExit m) = PrimState m primitive :: forall a. (State# (PrimState (WithEarlyExit m)) -> (# State# (PrimState (WithEarlyExit m)), a #)) -> WithEarlyExit m a primitive = m a -> WithEarlyExit m a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m a -> WithEarlyExit m a) -> ((State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a) -> (State# (PrimState m) -> (# State# (PrimState m), a #)) -> WithEarlyExit m a forall b c a. (b -> c) -> (a -> b) -> a -> c . (State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a forall a. (State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a forall (m :: * -> *) a. PrimMonad m => (State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a primitive {-# INLINE primitive #-} instance MonadST m => MonadST (WithEarlyExit m) where stToIO :: forall a. ST (PrimState (WithEarlyExit m)) a -> WithEarlyExit m a stToIO = m a -> WithEarlyExit m a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m a -> WithEarlyExit m a) -> (ST (PrimState m) a -> m a) -> ST (PrimState m) a -> WithEarlyExit m a forall b c a. (b -> c) -> (a -> b) -> a -> c . ST (PrimState m) a -> m a forall a. ST (PrimState m) a -> m a forall (m :: * -> *) a. MonadST m => ST (PrimState m) a -> m a stToIO withLiftST :: forall b. (forall s. (forall a. ST s a -> WithEarlyExit m a) -> b) -> b withLiftST forall s. (forall a. ST s a -> WithEarlyExit m a) -> b k = (forall a. ST (PrimState m) a -> WithEarlyExit m a) -> b forall s. (forall a. ST s a -> WithEarlyExit m a) -> b k ST (PrimState m) a -> WithEarlyExit m a ST (PrimState (WithEarlyExit m)) a -> WithEarlyExit m a forall a. ST (PrimState m) a -> WithEarlyExit m a forall a. ST (PrimState (WithEarlyExit m)) a -> WithEarlyExit m a forall (m :: * -> *) a. MonadST m => ST (PrimState m) a -> m a stToIO instance MonadMonotonicTimeNSec m => MonadMonotonicTimeNSec (WithEarlyExit m) where getMonotonicTimeNSec :: WithEarlyExit m Word64 getMonotonicTimeNSec = m Word64 -> WithEarlyExit m Word64 forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift m Word64 forall (m :: * -> *). MonadMonotonicTimeNSec m => m Word64 getMonotonicTimeNSec instance MonadMonotonicTime m => MonadMonotonicTime (WithEarlyExit m) where getMonotonicTime :: WithEarlyExit m Time getMonotonicTime = m Time -> WithEarlyExit m Time forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift m Time forall (m :: * -> *). MonadMonotonicTime m => m Time getMonotonicTime instance MonadDelay m => MonadDelay (WithEarlyExit m) where threadDelay :: Int -> WithEarlyExit m () threadDelay = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (Int -> m ()) -> Int -> WithEarlyExit m () forall b c a. (b -> c) -> (a -> b) -> a -> c . Int -> m () forall (m :: * -> *). MonadDelay m => Int -> m () threadDelay instance TimerSI.MonadDelay m => TimerSI.MonadDelay (WithEarlyExit m) where threadDelay :: DiffTime -> WithEarlyExit m () threadDelay = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (DiffTime -> m ()) -> DiffTime -> WithEarlyExit m () forall b c a. (b -> c) -> (a -> b) -> a -> c . DiffTime -> m () forall (m :: * -> *). MonadDelay m => DiffTime -> m () TimerSI.threadDelay instance (MonadEvaluate m, MonadCatch m) => MonadEvaluate (WithEarlyExit m) where evaluate :: forall a. a -> WithEarlyExit m a evaluate = m a -> WithEarlyExit m a forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m a -> WithEarlyExit m a) -> (a -> m a) -> a -> WithEarlyExit m a forall b c a. (b -> c) -> (a -> b) -> a -> c . a -> m a forall a. a -> m a forall (m :: * -> *) a. MonadEvaluate m => a -> m a evaluate instance MonadEventlog m => MonadEventlog (WithEarlyExit m) where traceEventIO :: String -> WithEarlyExit m () traceEventIO = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (String -> m ()) -> String -> WithEarlyExit m () forall b c a. (b -> c) -> (a -> b) -> a -> c . String -> m () forall (m :: * -> *). MonadEventlog m => String -> m () traceEventIO traceMarkerIO :: String -> WithEarlyExit m () traceMarkerIO = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (String -> m ()) -> String -> WithEarlyExit m () forall b c a. (b -> c) -> (a -> b) -> a -> c . String -> m () forall (m :: * -> *). MonadEventlog m => String -> m () traceMarkerIO instance MonadLabelledSTM m => MonadLabelledSTM (WithEarlyExit m) where labelTVar :: forall a. TVar (WithEarlyExit m) a -> String -> STM (WithEarlyExit m) () labelTVar = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TVar m a -> String -> STM m ()) -> TVar m a -> String -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TVar m a -> String -> STM m () forall a. TVar m a -> String -> STM m () forall (m :: * -> *) a. MonadLabelledSTM m => TVar m a -> String -> STM m () labelTVar labelTMVar :: forall a. TMVar (WithEarlyExit m) a -> String -> STM (WithEarlyExit m) () labelTMVar = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TMVar m a -> String -> STM m ()) -> TMVar m a -> String -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TMVar m a -> String -> STM m () forall a. TMVar m a -> String -> STM m () forall (m :: * -> *) a. MonadLabelledSTM m => TMVar m a -> String -> STM m () labelTMVar labelTQueue :: forall a. TQueue (WithEarlyExit m) a -> String -> STM (WithEarlyExit m) () labelTQueue = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TQueue m a -> String -> STM m ()) -> TQueue m a -> String -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TQueue m a -> String -> STM m () forall a. TQueue m a -> String -> STM m () forall (m :: * -> *) a. MonadLabelledSTM m => TQueue m a -> String -> STM m () labelTQueue labelTBQueue :: forall a. TBQueue (WithEarlyExit m) a -> String -> STM (WithEarlyExit m) () labelTBQueue = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TBQueue m a -> String -> STM m ()) -> TBQueue m a -> String -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TBQueue m a -> String -> STM m () forall a. TBQueue m a -> String -> STM m () forall (m :: * -> *) a. MonadLabelledSTM m => TBQueue m a -> String -> STM m () labelTBQueue labelTArray :: forall i e. (Ix i, Show i) => TArray (WithEarlyExit m) i e -> String -> STM (WithEarlyExit m) () labelTArray = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TArray m i e -> String -> STM m ()) -> TArray m i e -> String -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TArray m i e -> String -> STM m () forall i e. (Ix i, Show i) => TArray m i e -> String -> STM m () forall (m :: * -> *) i e. (MonadLabelledSTM m, Ix i, Show i) => TArray m i e -> String -> STM m () labelTArray labelTSem :: TSem (WithEarlyExit m) -> String -> STM (WithEarlyExit m) () labelTSem = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TSem m -> String -> STM m ()) -> TSem m -> String -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TSem m -> String -> STM m () forall (m :: * -> *). MonadLabelledSTM m => TSem m -> String -> STM m () labelTSem labelTChan :: forall a. TChan (WithEarlyExit m) a -> String -> STM (WithEarlyExit m) () labelTChan = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TChan m a -> String -> STM m ()) -> TChan m a -> String -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TChan m a -> String -> STM m () forall a. TChan m a -> String -> STM m () forall (m :: * -> *) a. MonadLabelledSTM m => TChan m a -> String -> STM m () labelTChan labelTVarIO :: forall a. TVar (WithEarlyExit m) a -> String -> WithEarlyExit m () labelTVarIO = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (TVar m a -> String -> m ()) -> TVar m a -> String -> WithEarlyExit m () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TVar m a -> String -> m () forall a. TVar m a -> String -> m () forall (m :: * -> *) a. MonadLabelledSTM m => TVar m a -> String -> m () labelTVarIO labelTMVarIO :: forall a. TMVar (WithEarlyExit m) a -> String -> WithEarlyExit m () labelTMVarIO = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (TMVar m a -> String -> m ()) -> TMVar m a -> String -> WithEarlyExit m () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TMVar m a -> String -> m () forall a. TMVar m a -> String -> m () forall (m :: * -> *) a. MonadLabelledSTM m => TMVar m a -> String -> m () labelTMVarIO labelTQueueIO :: forall a. TQueue (WithEarlyExit m) a -> String -> WithEarlyExit m () labelTQueueIO = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (TQueue m a -> String -> m ()) -> TQueue m a -> String -> WithEarlyExit m () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TQueue m a -> String -> m () forall a. TQueue m a -> String -> m () forall (m :: * -> *) a. MonadLabelledSTM m => TQueue m a -> String -> m () labelTQueueIO labelTBQueueIO :: forall a. TBQueue (WithEarlyExit m) a -> String -> WithEarlyExit m () labelTBQueueIO = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (TBQueue m a -> String -> m ()) -> TBQueue m a -> String -> WithEarlyExit m () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TBQueue m a -> String -> m () forall a. TBQueue m a -> String -> m () forall (m :: * -> *) a. MonadLabelledSTM m => TBQueue m a -> String -> m () labelTBQueueIO labelTArrayIO :: forall i e. (Ix i, Show i) => TArray (WithEarlyExit m) i e -> String -> WithEarlyExit m () labelTArrayIO = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (TArray m i e -> String -> m ()) -> TArray m i e -> String -> WithEarlyExit m () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TArray m i e -> String -> m () forall i e. (Ix i, Show i) => TArray m i e -> String -> m () forall (m :: * -> *) i e. (MonadLabelledSTM m, Ix i, Show i) => TArray m i e -> String -> m () labelTArrayIO labelTSemIO :: TSem (WithEarlyExit m) -> String -> WithEarlyExit m () labelTSemIO = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (TSem m -> String -> m ()) -> TSem m -> String -> WithEarlyExit m () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TSem m -> String -> m () forall (m :: * -> *). MonadLabelledSTM m => TSem m -> String -> m () labelTSemIO labelTChanIO :: forall a. TChan (WithEarlyExit m) a -> String -> WithEarlyExit m () labelTChanIO = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (TChan m a -> String -> m ()) -> TChan m a -> String -> WithEarlyExit m () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: TChan m a -> String -> m () forall a. TChan m a -> String -> m () forall (m :: * -> *) a. MonadLabelledSTM m => TChan m a -> String -> m () labelTChanIO instance MonadSay m => MonadSay (WithEarlyExit m) where say :: String -> WithEarlyExit m () say = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (String -> m ()) -> String -> WithEarlyExit m () forall b c a. (b -> c) -> (a -> b) -> a -> c . String -> m () forall (m :: * -> *). MonadSay m => String -> m () say instance (MonadInspectSTM m, Monad (InspectMonad m)) => MonadInspectSTM (WithEarlyExit m) where type InspectMonad (WithEarlyExit m) = InspectMonad m inspectTVar :: forall (proxy :: (* -> *) -> *) a. proxy (WithEarlyExit m) -> TVar (WithEarlyExit m) a -> InspectMonad (WithEarlyExit m) a inspectTVar proxy (WithEarlyExit m) _ = Proxy m -> TVar m a -> InspectMonad m a forall (m :: * -> *) (proxy :: (* -> *) -> *) a. MonadInspectSTM m => proxy m -> TVar m a -> InspectMonad m a forall (proxy :: (* -> *) -> *) a. proxy m -> TVar m a -> InspectMonad m a inspectTVar (forall {k} (t :: k). Proxy t forall (t :: * -> *). Proxy t Proxy @m) inspectTMVar :: forall (proxy :: (* -> *) -> *) a. proxy (WithEarlyExit m) -> TMVar (WithEarlyExit m) a -> InspectMonad (WithEarlyExit m) (Maybe a) inspectTMVar proxy (WithEarlyExit m) _ = Proxy m -> TMVar m a -> InspectMonad m (Maybe a) forall (m :: * -> *) (proxy :: (* -> *) -> *) a. MonadInspectSTM m => proxy m -> TMVar m a -> InspectMonad m (Maybe a) forall (proxy :: (* -> *) -> *) a. proxy m -> TMVar m a -> InspectMonad m (Maybe a) inspectTMVar (forall {k} (t :: k). Proxy t forall (t :: * -> *). Proxy t Proxy @m) instance MonadTraceSTM m => MonadTraceSTM (WithEarlyExit m) where traceTVar :: forall (proxy :: (* -> *) -> *) a. proxy (WithEarlyExit m) -> TVar (WithEarlyExit m) a -> (Maybe a -> a -> InspectMonad (WithEarlyExit m) TraceValue) -> STM (WithEarlyExit m) () traceTVar proxy (WithEarlyExit m) _ = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TVar m a -> (Maybe a -> a -> InspectMonad m TraceValue) -> STM m ()) -> TVar m a -> (Maybe a -> a -> InspectMonad m TraceValue) -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: Proxy m -> TVar m a -> (Maybe a -> a -> InspectMonad m TraceValue) -> STM m () forall (m :: * -> *) (proxy :: (* -> *) -> *) a. MonadTraceSTM m => proxy m -> TVar m a -> (Maybe a -> a -> InspectMonad m TraceValue) -> STM m () forall (proxy :: (* -> *) -> *) a. proxy m -> TVar m a -> (Maybe a -> a -> InspectMonad m TraceValue) -> STM m () traceTVar (forall {k} (t :: k). Proxy t forall (t :: * -> *). Proxy t Proxy @m) traceTMVar :: forall (proxy :: (* -> *) -> *) a. proxy (WithEarlyExit m) -> TMVar (WithEarlyExit m) a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad (WithEarlyExit m) TraceValue) -> STM (WithEarlyExit m) () traceTMVar proxy (WithEarlyExit m) _ = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> STM m ()) -> TMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: Proxy m -> TMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> STM m () forall (m :: * -> *) (proxy :: (* -> *) -> *) a. MonadTraceSTM m => proxy m -> TMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> STM m () forall (proxy :: (* -> *) -> *) a. proxy m -> TMVar m a -> (Maybe (Maybe a) -> Maybe a -> InspectMonad m TraceValue) -> STM m () traceTMVar (forall {k} (t :: k). Proxy t forall (t :: * -> *). Proxy t Proxy @m) traceTQueue :: forall (proxy :: (* -> *) -> *) a. proxy (WithEarlyExit m) -> TQueue (WithEarlyExit m) a -> (Maybe [a] -> [a] -> InspectMonad (WithEarlyExit m) TraceValue) -> STM (WithEarlyExit m) () traceTQueue proxy (WithEarlyExit m) _ = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m ()) -> TQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: Proxy m -> TQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m () forall (m :: * -> *) (proxy :: (* -> *) -> *) a. MonadTraceSTM m => proxy m -> TQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m () forall (proxy :: (* -> *) -> *) a. proxy m -> TQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m () traceTQueue (forall {k} (t :: k). Proxy t forall (t :: * -> *). Proxy t Proxy @m) traceTBQueue :: forall (proxy :: (* -> *) -> *) a. proxy (WithEarlyExit m) -> TBQueue (WithEarlyExit m) a -> (Maybe [a] -> [a] -> InspectMonad (WithEarlyExit m) TraceValue) -> STM (WithEarlyExit m) () traceTBQueue proxy (WithEarlyExit m) _ = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m ()) -> TBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: Proxy m -> TBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m () forall (m :: * -> *) (proxy :: (* -> *) -> *) a. MonadTraceSTM m => proxy m -> TBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m () forall (proxy :: (* -> *) -> *) a. proxy m -> TBQueue m a -> (Maybe [a] -> [a] -> InspectMonad m TraceValue) -> STM m () traceTBQueue (forall {k} (t :: k). Proxy t forall (t :: * -> *). Proxy t Proxy @m) traceTSem :: forall (proxy :: (* -> *) -> *). proxy (WithEarlyExit m) -> TSem (WithEarlyExit m) -> (Maybe Integer -> Integer -> InspectMonad (WithEarlyExit m) TraceValue) -> STM (WithEarlyExit m) () traceTSem proxy (WithEarlyExit m) _ = STM m () -> WithEarlyExit (STM m) () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (STM m () -> WithEarlyExit (STM m) ()) -> (TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> STM m ()) -> TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> WithEarlyExit (STM m) () forall y z x0 x1. (y -> z) -> (x0 -> x1 -> y) -> x0 -> x1 -> z .: Proxy m -> TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> STM m () forall (m :: * -> *) (proxy :: (* -> *) -> *). MonadTraceSTM m => proxy m -> TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> STM m () forall (proxy :: (* -> *) -> *). proxy m -> TSem m -> (Maybe Integer -> Integer -> InspectMonad m TraceValue) -> STM m () traceTSem (forall {k} (t :: k). Proxy t forall (t :: * -> *). Proxy t Proxy @m) {------------------------------------------------------------------------------- Finally, the consensus IOLike wrapper -------------------------------------------------------------------------------} instance ( IOLike m , forall a. NoThunks (StrictTVar (WithEarlyExit m) a) , forall a. NoThunks (StrictSVar (WithEarlyExit m) a) , forall a. NoThunks (StrictMVar (WithEarlyExit m) a) ) => IOLike (WithEarlyExit m) where forgetSignKeyKES :: forall v. KESAlgorithm v => SignKeyKES v -> WithEarlyExit m () forgetSignKeyKES = m () -> WithEarlyExit m () forall (m :: * -> *) a. Monad m => m a -> WithEarlyExit m a forall (t :: (* -> *) -> * -> *) (m :: * -> *) a. (MonadTrans t, Monad m) => m a -> t m a lift (m () -> WithEarlyExit m ()) -> (SignKeyKES v -> m ()) -> SignKeyKES v -> WithEarlyExit m () forall b c a. (b -> c) -> (a -> b) -> a -> c . SignKeyKES v -> m () forall v. KESAlgorithm v => SignKeyKES v -> m () forall (m :: * -> *) v. (IOLike m, KESAlgorithm v) => SignKeyKES v -> m () forgetSignKeyKES