Safe Haskell | None |
---|---|
Language | Haskell2010 |
Util.IOExtra
Synopsis
- requireM :: (HasCallStack, MonadCatch m, MonadLogger m) => String -> Bool -> m ()
- tryAndLogIO :: (HasCallStack, MonadCatch m, MonadLogger m) => m a -> m (Maybe a)
- tryAndLogAll :: forall a m. (HasCallStack, MonadCatch m, MonadLogger m) => m a -> m (Maybe a)
- catchAndLogIO :: (HasCallStack, MonadCatch m, MonadLogger m) => m a -> (IOError -> m a) -> m a
- catchAndLogAll :: (HasCallStack, MonadCatch m, MonadLogger m) => m a -> (SomeException -> m a) -> m a
- onExceptionLog :: (HasCallStack, MonadCatch m, MonadLogger m) => m a -> m b -> m a
- bracketOnErrorLog :: (HasCallStack, MonadMask m, MonadLogger m) => m a -> (a -> m b) -> (a -> m c) -> m c
- handleAndLogAll :: (HasCallStack, MonadCatch m, MonadLogger m) => (SomeException -> m a) -> m a -> m a
- catchAndLog :: (HasCallStack, MonadCatch m, MonadLogger m, Exception e) => m a -> (e -> m a) -> m a
- handleAndLog :: (HasCallStack, MonadCatch m, MonadLogger m, Exception e) => (e -> m a) -> m a -> m a
- logWarnStr :: (HasCallStack, MonadLogger m) => String -> m ()
- logInfoStr :: (HasCallStack, MonadLogger m) => String -> m ()
- logErrorStr :: (HasCallStack, MonadLogger m) => String -> m ()
- logAndThrow :: (HasCallStack, MonadMask m, MonadLogger m, Exception e) => e -> m a
- logInfoShow :: (HasCallStack, Show s, MonadLogger m) => s -> m ()
- logErrorShow :: (HasCallStack, Show s, MonadLogger m) => s -> m ()
- throwLeftM :: (HasCallStack, MonadMask m, MonadLogger m, Exception e) => m (Either e r) -> m r
- throwNothingM :: (HasCallStack, MonadLogger m, MonadCatch m) => m (Maybe r) -> m r
- data ErrMsg a = ErrMsg String a
- data OneBillionDollarBug = OneBillionDollarBug
- data ThreadId
- waitBothSTM :: Async a -> Async b -> STM (a, b)
- waitEitherSTM_ :: Async a -> Async b -> STM ()
- waitEitherSTM :: Async a -> Async b -> STM (Either a b)
- waitEitherCatchSTM :: Async a -> Async b -> STM (Either (Either SomeException a) (Either SomeException b))
- waitAnySTM :: [Async a] -> STM (Async a, a)
- waitAnyCatchSTM :: [Async a] -> STM (Async a, Either SomeException a)
- pollSTM :: Async a -> STM (Maybe (Either SomeException a))
- waitCatchSTM :: Async a -> STM (Either SomeException a)
- waitSTM :: Async a -> STM a
- compareAsyncs :: Async a -> Async b -> Ordering
- data Async a
- data AsyncCancelled = AsyncCancelled
- data ExceptionInLinkedThread = ExceptionInLinkedThread (Async a) SomeException
- rtsSupportsBoundThreads :: Bool
- data Chan a
- data QSem
- data QSemN
- class Monad m => MonadIO (m :: Type -> Type) where
- errorBadArgument :: a
- errorMissingArgument :: a
- errorShortFormat :: a
- errorBadFormat :: Char -> a
- perror :: String -> a
- formatRealFloat :: RealFloat a => a -> FieldFormatter
- formatInteger :: Integer -> FieldFormatter
- formatInt :: (Integral a, Bounded a) => a -> FieldFormatter
- formatString :: IsChar a => [a] -> FieldFormatter
- formatChar :: Char -> FieldFormatter
- vFmt :: Char -> FieldFormat -> FieldFormat
- hPrintf :: HPrintfType r => Handle -> String -> r
- printf :: PrintfType r => String -> r
- class PrintfType t
- class HPrintfType t
- class PrintfArg a where
- formatArg :: a -> FieldFormatter
- parseFormat :: a -> ModifierParser
- class IsChar c where
- data FormatAdjustment
- data FormatSign
- data FieldFormat = FieldFormat {}
- data FormatParse = FormatParse {}
- type FieldFormatter = FieldFormat -> ShowS
- type ModifierParser = String -> FormatParse
- unless :: Applicative f => Bool -> f () -> f ()
- newtype AssertionFailed = AssertionFailed String
- class (Typeable e, Show e) => Exception e where
- toException :: e -> SomeException
- fromException :: SomeException -> Maybe e
- displayException :: e -> String
- fromJust :: HasCallStack => Maybe a -> a
- isJust :: Maybe a -> Bool
- void :: Functor f => f a -> f ()
- data MVar a
- when :: Applicative f => Bool -> f () -> f ()
- data SomeException = Exception e => SomeException e
- class MonadIO m => MonadUnliftIO (m :: Type -> Type)
- data ResourceT (m :: Type -> Type) a
- class MonadIO m => MonadResource (m :: Type -> Type) where
- liftResourceT :: ResourceT IO a -> m a
- runResourceT :: MonadUnliftIO m => ResourceT m a -> m a
- class Monad m => MonadThrow (m :: Type -> Type) where
- bracketOnError :: MonadMask m => m a -> (a -> m c) -> (a -> m b) -> m b
- finally :: MonadMask m => m a -> m b -> m a
- bracket_ :: MonadMask m => m a -> m c -> m b -> m b
- bracket :: MonadMask m => m a -> (a -> m c) -> (a -> m b) -> m b
- onError :: MonadMask m => m a -> m b -> m a
- onException :: MonadCatch m => m a -> m b -> m a
- catches :: (Foldable f, MonadCatch m) => m a -> f (Handler m a) -> m a
- tryJust :: (MonadCatch m, Exception e) => (e -> Maybe b) -> m a -> m (Either b a)
- try :: (MonadCatch m, Exception e) => m a -> m (Either e a)
- handleJust :: (MonadCatch m, Exception e) => (e -> Maybe b) -> (b -> m a) -> m a -> m a
- handleIf :: (MonadCatch m, Exception e) => (e -> Bool) -> (e -> m a) -> m a -> m a
- handleAll :: MonadCatch m => (SomeException -> m a) -> m a -> m a
- handleIOError :: MonadCatch m => (IOError -> m a) -> m a -> m a
- handle :: (MonadCatch m, Exception e) => (e -> m a) -> m a -> m a
- catchJust :: (MonadCatch m, Exception e) => (e -> Maybe b) -> m a -> (b -> m a) -> m a
- catchIf :: (MonadCatch m, Exception e) => (e -> Bool) -> m a -> (e -> m a) -> m a
- catchIOError :: MonadCatch m => m a -> (IOError -> m a) -> m a
- catchAll :: MonadCatch m => m a -> (SomeException -> m a) -> m a
- uninterruptibleMask_ :: MonadMask m => m a -> m a
- mask_ :: MonadMask m => m a -> m a
- class MonadThrow m => MonadCatch (m :: Type -> Type) where
- class MonadCatch m => MonadMask (m :: Type -> Type) where
- mask :: ((forall a. m a -> m a) -> m b) -> m b
- uninterruptibleMask :: ((forall a. m a -> m a) -> m b) -> m b
- generalBracket :: m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c)
- data ExitCase a
- data Handler (m :: Type -> Type) a = Exception e => Handler (e -> m a)
- type family StM (m :: Type -> Type) a
- replicateConcurrently_ :: MonadBaseControl IO m => Int -> m a -> m ()
- replicateConcurrently :: MonadBaseControl IO m => Int -> m a -> m [a]
- forConcurrently_ :: (Foldable t, MonadBaseControl IO m) => t a -> (a -> m b) -> m ()
- forConcurrently :: (Traversable t, MonadBaseControl IO m) => t a -> (a -> m b) -> m (t b)
- mapConcurrently_ :: (Foldable t, MonadBaseControl IO m) => (a -> m b) -> t a -> m ()
- mapConcurrently :: (Traversable t, MonadBaseControl IO m) => (a -> m b) -> t a -> m (t b)
- concurrently_ :: MonadBaseControl IO m => m a -> m b -> m ()
- concurrently :: MonadBaseControl IO m => m a -> m b -> m (a, b)
- race_ :: MonadBaseControl IO m => m a -> m b -> m ()
- race :: MonadBaseControl IO m => m a -> m b -> m (Either a b)
- link2 :: MonadBase IO m => Async a -> Async b -> m ()
- link :: MonadBase IO m => Async a -> m ()
- waitBoth :: MonadBaseControl IO m => Async (StM m a) -> Async (StM m b) -> m (a, b)
- waitEither_ :: MonadBase IO m => Async a -> Async b -> m ()
- waitEitherCatchCancel :: MonadBaseControl IO m => Async (StM m a) -> Async (StM m b) -> m (Either (Either SomeException a) (Either SomeException b))
- waitEitherCancel :: MonadBaseControl IO m => Async (StM m a) -> Async (StM m b) -> m (Either a b)
- waitEitherCatch :: MonadBaseControl IO m => Async (StM m a) -> Async (StM m b) -> m (Either (Either SomeException a) (Either SomeException b))
- waitEither :: MonadBaseControl IO m => Async (StM m a) -> Async (StM m b) -> m (Either a b)
- waitAnyCatchCancel :: MonadBaseControl IO m => [Async (StM m a)] -> m (Async (StM m a), Either SomeException a)
- waitAnyCancel :: MonadBaseControl IO m => [Async (StM m a)] -> m (Async (StM m a), a)
- waitAnyCatch :: MonadBaseControl IO m => [Async (StM m a)] -> m (Async (StM m a), Either SomeException a)
- waitAny :: MonadBaseControl IO m => [Async (StM m a)] -> m (Async (StM m a), a)
- waitCatch :: MonadBaseControl IO m => Async (StM m a) -> m (Either SomeException a)
- uninterruptibleCancel :: MonadBase IO m => Async a -> m ()
- cancelWith :: (MonadBase IO m, Exception e) => Async a -> e -> m ()
- cancel :: MonadBase IO m => Async a -> m ()
- poll :: MonadBaseControl IO m => Async (StM m a) -> m (Maybe (Either SomeException a))
- wait :: MonadBaseControl IO m => Async (StM m a) -> m a
- withAsyncOnWithUnmask :: MonadBaseControl IO m => Int -> ((forall c. m c -> m c) -> m a) -> (Async (StM m a) -> m b) -> m b
- withAsyncWithUnmask :: MonadBaseControl IO m => ((forall c. m c -> m c) -> m a) -> (Async (StM m a) -> m b) -> m b
- withAsyncOn :: MonadBaseControl IO m => Int -> m a -> (Async (StM m a) -> m b) -> m b
- withAsyncBound :: MonadBaseControl IO m => m a -> (Async (StM m a) -> m b) -> m b
- withAsync :: MonadBaseControl IO m => m a -> (Async (StM m a) -> m b) -> m b
- asyncOnWithUnmask :: MonadBaseControl IO m => Int -> ((forall b. m b -> m b) -> m a) -> m (Async (StM m a))
- asyncWithUnmask :: MonadBaseControl IO m => ((forall b. m b -> m b) -> m a) -> m (Async (StM m a))
- asyncOn :: MonadBaseControl IO m => Int -> m a -> m (Async (StM m a))
- asyncBound :: MonadBaseControl IO m => m a -> m (Async (StM m a))
- async :: MonadBaseControl IO m => m a -> m (Async (StM m a))
- newtype Concurrently (m :: Type -> Type) a = Concurrently {
- runConcurrently :: m a
- liftBaseOp_ :: MonadBaseControl b m => (b (StM m a) -> b (StM m c)) -> m a -> m c
- mkWeakThreadId :: MonadBase IO m => ThreadId -> m (Weak ThreadId)
- runInUnboundThread :: MonadBaseControl IO m => m a -> m a
- runInBoundThread :: MonadBaseControl IO m => m a -> m a
- isCurrentThreadBound :: MonadBase IO m => m Bool
- forkOS :: MonadBaseControl IO m => m () -> m ThreadId
- threadWaitWrite :: MonadBase IO m => Fd -> m ()
- threadWaitRead :: MonadBase IO m => Fd -> m ()
- threadDelay :: MonadBase IO m => Int -> m ()
- yield :: MonadBase IO m => m ()
- threadCapability :: MonadBase IO m => ThreadId -> m (Int, Bool)
- setNumCapabilities :: MonadBase IO m => Int -> m ()
- getNumCapabilities :: MonadBase IO m => m Int
- forkOnWithUnmask :: MonadBaseControl IO m => Int -> ((forall a. m a -> m a) -> m ()) -> m ThreadId
- forkOn :: MonadBaseControl IO m => Int -> m () -> m ThreadId
- killThread :: MonadBase IO m => ThreadId -> m ()
- forkFinally :: MonadBaseControl IO m => m a -> (Either SomeException a -> m ()) -> m ThreadId
- forkWithUnmask :: MonadBaseControl IO m => ((forall a. m a -> m a) -> m ()) -> m ThreadId
- fork :: MonadBaseControl IO m => m () -> m ThreadId
- myThreadId :: MonadBase IO m => m ThreadId
- throwTo :: (MonadBase IO m, Exception e) => ThreadId -> e -> m ()
- signalQSemN :: MonadBase IO m => QSemN -> Int -> m ()
- waitQSemN :: MonadBase IO m => QSemN -> Int -> m ()
- newQSemN :: MonadBase IO m => Int -> m QSemN
- signalQSem :: MonadBase IO m => QSem -> m ()
- waitQSem :: MonadBase IO m => QSem -> m ()
- newQSem :: MonadBase IO m => Int -> m QSem
- tryReadMVar :: MonadBase IO m => MVar a -> m (Maybe a)
- withMVarMasked :: MonadBaseControl IO m => MVar a -> (a -> m b) -> m b
- mkWeakMVar :: MonadBaseControl IO m => MVar a -> m () -> m (Weak (MVar a))
- modifyMVarMasked :: MonadBaseControl IO m => MVar a -> (a -> m (a, b)) -> m b
- modifyMVarMasked_ :: MonadBaseControl IO m => MVar a -> (a -> m a) -> m ()
- modifyMVar :: MonadBaseControl IO m => MVar a -> (a -> m (a, b)) -> m b
- modifyMVar_ :: MonadBaseControl IO m => MVar a -> (a -> m a) -> m ()
- withMVar :: MonadBaseControl IO m => MVar a -> (a -> m b) -> m b
- isEmptyMVar :: MonadBase IO m => MVar a -> m Bool
- tryPutMVar :: MonadBase IO m => MVar a -> a -> m Bool
- tryTakeMVar :: MonadBase IO m => MVar a -> m (Maybe a)
- swapMVar :: MonadBase IO m => MVar a -> a -> m a
- readMVar :: MonadBase IO m => MVar a -> m a
- putMVar :: MonadBase IO m => MVar a -> a -> m ()
- takeMVar :: MonadBase IO m => MVar a -> m a
- newMVar :: MonadBase IO m => a -> m (MVar a)
- newEmptyMVar :: MonadBase IO m => m (MVar a)
- writeList2Chan :: MonadBase IO m => Chan a -> [a] -> m ()
- getChanContents :: MonadBase IO m => Chan a -> m [a]
- dupChan :: MonadBase IO m => Chan a -> m (Chan a)
- readChan :: MonadBase IO m => Chan a -> m a
- writeChan :: MonadBase IO m => Chan a -> a -> m ()
- newChan :: MonadBase IO m => m (Chan a)
- liftThrough :: (MonadTransControl t, Monad (t m), Monad m) => (m (StT t a) -> m (StT t b)) -> t m a -> t m b
- liftBaseOpDiscard :: MonadBaseControl b m => ((a -> b ()) -> b c) -> (a -> m ()) -> m c
- liftBaseDiscard :: MonadBaseControl b m => (b () -> b a) -> m () -> m a
- liftBaseOp :: MonadBaseControl b m => ((a -> b (StM m c)) -> b (StM m d)) -> (a -> m c) -> m d
- captureM :: forall (b :: Type -> Type) m. MonadBaseControl b m => m (StM m ())
- captureT :: forall t (m :: Type -> Type). (MonadTransControl t, Monad (t m), Monad m) => t m (StT t ())
- embed_ :: MonadBaseControl b m => (a -> m ()) -> m (a -> b ())
- embed :: MonadBaseControl b m => (a -> m c) -> m (a -> b (StM m c))
- control :: MonadBaseControl b m => (RunInBase m b -> b (StM m a)) -> m a
- defaultRestoreM :: forall t (b :: Type -> Type) (m :: Type -> Type) a. (MonadTransControl t, MonadBaseControl b m) => ComposeSt t m a -> t m a
- defaultLiftBaseWith :: forall t b (m :: Type -> Type) a. (MonadTransControl t, MonadBaseControl b m) => (RunInBaseDefault t m b -> b a) -> t m a
- defaultRestoreT2 :: forall m (n' :: (Type -> Type) -> Type -> Type) n a t. (Monad m, Monad (n' m), MonadTransControl n, MonadTransControl n') => (n (n' m) a -> t m a) -> m (StT n' (StT n a)) -> t m a
- defaultLiftWith2 :: forall m (n' :: (Type -> Type) -> Type -> Type) n t a. (Monad m, Monad (n' m), MonadTransControl n, MonadTransControl n') => (forall b. n (n' m) b -> t m b) -> (forall (o :: Type -> Type) b. t o b -> n (n' o) b) -> (RunDefault2 t n n' -> m a) -> t m a
- defaultRestoreT :: (Monad m, MonadTransControl n) => (n m a -> t m a) -> m (StT n a) -> t m a
- defaultLiftWith :: (Monad m, MonadTransControl n) => (forall b. n m b -> t m b) -> (forall (o :: Type -> Type) b. t o b -> n o b) -> (RunDefault t n -> m a) -> t m a
- type family StT (t :: (Type -> Type) -> Type -> Type) a
- class MonadTrans t => MonadTransControl (t :: (Type -> Type) -> Type -> Type) where
- type Run (t :: (Type -> Type) -> Type -> Type) = forall (n :: Type -> Type) b. Monad n => t n b -> n (StT t b)
- type RunDefault (t :: (Type -> Type) -> Type -> Type) (t' :: (Type -> Type) -> Type -> Type) = forall (n :: Type -> Type) b. Monad n => t n b -> n (StT t' b)
- type RunDefault2 (t :: (Type -> Type) -> Type -> Type) (n :: (Type -> Type) -> Type -> Type) (n' :: (Type -> Type) -> Type -> Type) = forall (m :: Type -> Type) b. (Monad m, Monad (n' m)) => t m b -> m (StT n' (StT n b))
- class MonadBase b m => MonadBaseControl (b :: Type -> Type) (m :: Type -> Type) | m -> b where
- type RunInBase (m :: Type -> Type) (b :: Type -> Type) = forall a. m a -> b (StM m a)
- type ComposeSt (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a = StM m (StT t a)
- type RunInBaseDefault (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) (b :: Type -> Type) = forall a. t m a -> b (ComposeSt t m a)
- logError :: (HasCallStack, MonadLogger m) => Text -> m ()
- logInfo :: (HasCallStack, MonadLogger m) => Text -> m ()
- logErrorCS :: MonadLogger m => CallStack -> Text -> m ()
- logWarnCS :: MonadLogger m => CallStack -> Text -> m ()
- logInfoCS :: MonadLogger m => CallStack -> Text -> m ()
- class Monad m => MonadLogger (m :: Type -> Type)
- class (MonadLogger m, MonadIO m) => MonadLoggerIO (m :: Type -> Type)
- data LoggingT (m :: Type -> Type) a
- withInternalState :: (InternalState -> m a) -> ResourceT m a
- runInternalState :: ResourceT m a -> InternalState -> m a
- getInternalState :: forall (m :: Type -> Type). Monad m => ResourceT m InternalState
- closeInternalState :: MonadIO m => InternalState -> m ()
- createInternalState :: MonadIO m => m InternalState
- resourceForkIO :: forall (m :: Type -> Type). MonadUnliftIO m => ResourceT m () -> ResourceT m ThreadId
- resourceForkWith :: forall (m :: Type -> Type) a. MonadUnliftIO m => (IO () -> IO a) -> ResourceT m () -> ResourceT m a
- joinResourceT :: forall (m :: Type -> Type) a. ResourceT (ResourceT m) a -> ResourceT m a
- runResourceTChecked :: MonadUnliftIO m => ResourceT m a -> m a
- resourceMask :: MonadResource m => ((forall a. ResourceT IO a -> ResourceT IO a) -> ResourceT IO b) -> m b
- allocate_ :: MonadResource m => IO a -> IO () -> m ReleaseKey
- allocate :: MonadResource m => IO a -> (a -> IO ()) -> m (ReleaseKey, a)
- unprotect :: MonadIO m => ReleaseKey -> m (Maybe (IO ()))
- release :: MonadIO m => ReleaseKey -> m ()
- register :: MonadResource m => IO () -> m ReleaseKey
- type MonadResourceBase = MonadUnliftIO
- type InternalState = IORef ReleaseMap
- transResourceT :: (m a -> n b) -> ResourceT m a -> ResourceT n b
- data ReleaseKey
- type ResIO = ResourceT IO
- data InvalidAccess = InvalidAccess {}
- data ResourceCleanupException = ResourceCleanupException {}
Documentation
requireM :: (HasCallStack, MonadCatch m, MonadLogger m) => String -> Bool -> m () Source #
tryAndLogIO :: (HasCallStack, MonadCatch m, MonadLogger m) => m a -> m (Maybe a) Source #
tryAndLogAll :: forall a m. (HasCallStack, MonadCatch m, MonadLogger m) => m a -> m (Maybe a) Source #
catchAndLogIO :: (HasCallStack, MonadCatch m, MonadLogger m) => m a -> (IOError -> m a) -> m a Source #
catchAndLogAll :: (HasCallStack, MonadCatch m, MonadLogger m) => m a -> (SomeException -> m a) -> m a Source #
onExceptionLog :: (HasCallStack, MonadCatch m, MonadLogger m) => m a -> m b -> m a Source #
bracketOnErrorLog :: (HasCallStack, MonadMask m, MonadLogger m) => m a -> (a -> m b) -> (a -> m c) -> m c Source #
handleAndLogAll :: (HasCallStack, MonadCatch m, MonadLogger m) => (SomeException -> m a) -> m a -> m a Source #
catchAndLog :: (HasCallStack, MonadCatch m, MonadLogger m, Exception e) => m a -> (e -> m a) -> m a Source #
handleAndLog :: (HasCallStack, MonadCatch m, MonadLogger m, Exception e) => (e -> m a) -> m a -> m a Source #
logWarnStr :: (HasCallStack, MonadLogger m) => String -> m () Source #
logInfoStr :: (HasCallStack, MonadLogger m) => String -> m () Source #
logErrorStr :: (HasCallStack, MonadLogger m) => String -> m () Source #
logAndThrow :: (HasCallStack, MonadMask m, MonadLogger m, Exception e) => e -> m a Source #
logInfoShow :: (HasCallStack, Show s, MonadLogger m) => s -> m () Source #
logErrorShow :: (HasCallStack, Show s, MonadLogger m) => s -> m () Source #
throwLeftM :: (HasCallStack, MonadMask m, MonadLogger m, Exception e) => m (Either e r) -> m r Source #
throwNothingM :: (HasCallStack, MonadLogger m, MonadCatch m) => m (Maybe r) -> m r Source #
Instances
Show a => Show (ErrMsg a) Source # | |
Exception a => Exception (ErrMsg a) Source # | |
Defined in Util.IOExtra Methods toException :: ErrMsg a -> SomeException # fromException :: SomeException -> Maybe (ErrMsg a) # displayException :: ErrMsg a -> String # |
data OneBillionDollarBug Source #
Constructors
OneBillionDollarBug |
Instances
Show OneBillionDollarBug Source # | |
Defined in Util.IOExtra Methods showsPrec :: Int -> OneBillionDollarBug -> ShowS # show :: OneBillionDollarBug -> String # showList :: [OneBillionDollarBug] -> ShowS # | |
Exception OneBillionDollarBug Source # | |
Defined in Util.IOExtra Methods toException :: OneBillionDollarBug -> SomeException # fromException :: SomeException -> Maybe OneBillionDollarBug # |
A ThreadId
is an abstract type representing a handle to a thread.
ThreadId
is an instance of Eq
, Ord
and Show
, where
the Ord
instance implements an arbitrary total ordering over
ThreadId
s. The Show
instance lets you convert an arbitrary-valued
ThreadId
to string form; showing a ThreadId
value is occasionally
useful when debugging or diagnosing the behaviour of a concurrent
program.
Note: in GHC, if you have a ThreadId
, you essentially have
a pointer to the thread itself. This means the thread itself can't be
garbage collected until you drop the ThreadId
.
This misfeature will hopefully be corrected at a later date.
Instances
Eq ThreadId | Since: base-4.2.0.0 |
Ord ThreadId | Since: base-4.2.0.0 |
Defined in GHC.Conc.Sync | |
Show ThreadId | Since: base-4.2.0.0 |
NFData ThreadId | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
Hashable ThreadId | |
Defined in Data.Hashable.Class |
waitBothSTM :: Async a -> Async b -> STM (a, b) #
A version of waitBoth
that can be used inside an STM transaction.
Since: async-2.1.0
waitEitherSTM_ :: Async a -> Async b -> STM () #
A version of waitEither_
that can be used inside an STM transaction.
Since: async-2.1.0
waitEitherSTM :: Async a -> Async b -> STM (Either a b) #
A version of waitEither
that can be used inside an STM transaction.
Since: async-2.1.0
waitEitherCatchSTM :: Async a -> Async b -> STM (Either (Either SomeException a) (Either SomeException b)) #
A version of waitEitherCatch
that can be used inside an STM transaction.
Since: async-2.1.0
waitAnySTM :: [Async a] -> STM (Async a, a) #
A version of waitAny
that can be used inside an STM transaction.
Since: async-2.1.0
waitAnyCatchSTM :: [Async a] -> STM (Async a, Either SomeException a) #
A version of waitAnyCatch
that can be used inside an STM transaction.
Since: async-2.1.0
pollSTM :: Async a -> STM (Maybe (Either SomeException a)) #
A version of poll
that can be used inside an STM transaction.
waitCatchSTM :: Async a -> STM (Either SomeException a) #
A version of waitCatch
that can be used inside an STM transaction.
compareAsyncs :: Async a -> Async b -> Ordering #
Compare two Asyncs that may have different types by their ThreadId.
An asynchronous action spawned by async
or withAsync
.
Asynchronous actions are executed in a separate thread, and
operations are provided for waiting for asynchronous actions to
complete and obtaining their results (see e.g. wait
).
Instances
Functor Async | |
Eq (Async a) | |
Ord (Async a) | |
Defined in Control.Concurrent.Async | |
Hashable (Async a) | |
Defined in Control.Concurrent.Async |
data AsyncCancelled #
The exception thrown by cancel
to terminate a thread.
Constructors
AsyncCancelled |
Instances
Eq AsyncCancelled | |
Defined in Control.Concurrent.Async Methods (==) :: AsyncCancelled -> AsyncCancelled -> Bool # (/=) :: AsyncCancelled -> AsyncCancelled -> Bool # | |
Show AsyncCancelled | |
Defined in Control.Concurrent.Async Methods showsPrec :: Int -> AsyncCancelled -> ShowS # show :: AsyncCancelled -> String # showList :: [AsyncCancelled] -> ShowS # | |
Exception AsyncCancelled | |
Defined in Control.Concurrent.Async Methods toException :: AsyncCancelled -> SomeException # |
data ExceptionInLinkedThread #
Constructors
ExceptionInLinkedThread (Async a) SomeException |
Instances
Show ExceptionInLinkedThread | |
Defined in Control.Concurrent.Async Methods showsPrec :: Int -> ExceptionInLinkedThread -> ShowS # show :: ExceptionInLinkedThread -> String # showList :: [ExceptionInLinkedThread] -> ShowS # | |
Exception ExceptionInLinkedThread | |
Defined in Control.Concurrent.Async |
rtsSupportsBoundThreads :: Bool #
True
if bound threads are supported.
If rtsSupportsBoundThreads
is False
, isCurrentThreadBound
will always return False
and both forkOS
and runInBoundThread
will
fail.
Chan
is an abstract type representing an unbounded FIFO channel.
class Monad m => MonadIO (m :: Type -> Type) where #
Monads in which IO
computations may be embedded.
Any monad built by applying a sequence of monad transformers to the
IO
monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO
is a transformer of monads:
Instances
errorBadArgument :: a #
Calls perror
to indicate that there is a type
error or similar in the given argument.
Since: base-4.7.0.0
errorMissingArgument :: a #
Calls perror
to indicate that there is a missing
argument in the argument list.
Since: base-4.7.0.0
errorShortFormat :: a #
Calls perror
to indicate that the format string ended
early.
Since: base-4.7.0.0
errorBadFormat :: Char -> a #
Calls perror
to indicate an unknown format letter for
a given type.
Since: base-4.7.0.0
Raises an error
with a printf-specific prefix on the
message string.
Since: base-4.7.0.0
formatRealFloat :: RealFloat a => a -> FieldFormatter #
Formatter for RealFloat
values.
Since: base-4.7.0.0
formatInteger :: Integer -> FieldFormatter #
Formatter for Integer
values.
Since: base-4.7.0.0
formatInt :: (Integral a, Bounded a) => a -> FieldFormatter #
Formatter for Int
values.
Since: base-4.7.0.0
formatString :: IsChar a => [a] -> FieldFormatter #
Formatter for String
values.
Since: base-4.7.0.0
formatChar :: Char -> FieldFormatter #
Formatter for Char
values.
Since: base-4.7.0.0
vFmt :: Char -> FieldFormat -> FieldFormat #
Substitute a 'v' format character with the given
default format character in the FieldFormat
. A
convenience for user-implemented types, which should
support "%v".
Since: base-4.7.0.0
hPrintf :: HPrintfType r => Handle -> String -> r #
printf :: PrintfType r => String -> r #
Format a variable number of arguments with the C-style formatting string.
>>>
printf "%s, %d, %.4f" "hello" 123 pi
hello, 123, 3.1416
The return value is either String
or (
(which
should be IO
a)(
, but Haskell's type system
makes this hard).IO
())
The format string consists of ordinary characters and
conversion specifications, which specify how to format
one of the arguments to printf
in the output string. A
format specification is introduced by the %
character;
this character can be self-escaped into the format string
using %%
. A format specification ends with a
format character that provides the primary information about
how to format the value. The rest of the conversion
specification is optional. In order, one may have flag
characters, a width specifier, a precision specifier, and
type-specific modifier characters.
Unlike C printf(3)
, the formatting of this printf
is driven by the argument type; formatting is type specific. The
types formatted by printf
"out of the box" are:
printf
is also extensible to support other types: see below.
A conversion specification begins with the
character %
, followed by zero or more of the following flags:
- left adjust (default is right adjust) + always use a sign (+ or -) for signed conversions space leading space for positive numbers in signed conversions 0 pad with zeros rather than spaces # use an \"alternate form\": see below
When both flags are given, -
overrides 0
and +
overrides space.
A negative width specifier in a *
conversion is treated as
positive but implies the left adjust flag.
The "alternate form" for unsigned radix conversions is
as in C printf(3)
:
%o prefix with a leading 0 if needed %x prefix with a leading 0x if nonzero %X prefix with a leading 0X if nonzero %b prefix with a leading 0b if nonzero %[eEfFgG] ensure that the number contains a decimal point
Any flags are followed optionally by a field width:
num field width * as num, but taken from argument list
The field width is a minimum, not a maximum: it will be expanded as needed to avoid mutilating a value.
Any field width is followed optionally by a precision:
.num precision . same as .0 .* as num, but taken from argument list
Negative precision is taken as 0. The meaning of the precision depends on the conversion type.
Integral minimum number of digits to show RealFloat number of digits after the decimal point String maximum number of characters
The precision for Integral types is accomplished by zero-padding. If both precision and zero-pad are given for an Integral field, the zero-pad is ignored.
Any precision is followed optionally for Integral types by a width modifier; the only use of this modifier being to set the implicit size of the operand for conversion of a negative operand to unsigned:
hh Int8 h Int16 l Int32 ll Int64 L Int64
The specification ends with a format character:
c character Integral d decimal Integral o octal Integral x hexadecimal Integral X hexadecimal Integral b binary Integral u unsigned decimal Integral f floating point RealFloat F floating point RealFloat g general format float RealFloat G general format float RealFloat e exponent format float RealFloat E exponent format float RealFloat s string String v default format any type
The "%v" specifier is provided for all built-in types, and should be provided for user-defined type formatters as well. It picks a "best" representation for the given type. For the built-in types the "%v" specifier is converted as follows:
c Char u other unsigned Integral d other signed Integral g RealFloat s String
Mismatch between the argument types and the format string, as well as any other syntactic or semantic errors in the format string, will cause an exception to be thrown at runtime.
Note that the formatting for RealFloat
types is
currently a bit different from that of C printf(3)
,
conforming instead to showEFloat
,
showFFloat
and showGFloat
(and their
alternate versions showFFloatAlt
and
showGFloatAlt
). This is hard to fix: the fixed
versions would format in a backward-incompatible way.
In any case the Haskell behavior is generally more
sensible than the C behavior. A brief summary of some
key differences:
- Haskell
printf
never uses the default "6-digit" precision used by C printf. - Haskell
printf
treats the "precision" specifier as indicating the number of digits after the decimal point. - Haskell
printf
prints the exponent of e-format numbers without a gratuitous plus sign, and with the minimum possible number of digits. - Haskell
printf
will place a zero after a decimal point when possible.
class PrintfType t #
The PrintfType
class provides the variable argument magic for
printf
. Its implementation is intentionally not visible from
this module. If you attempt to pass an argument of a type which
is not an instance of this class to printf
or hPrintf
, then
the compiler will report it as a missing instance of PrintfArg
.
Minimal complete definition
spr
Instances
IsChar c => PrintfType [c] | Since: base-2.1 |
Defined in Text.Printf | |
a ~ () => PrintfType (IO a) | Since: base-4.7.0.0 |
Defined in Text.Printf | |
(PrintfArg a, PrintfType r) => PrintfType (a -> r) | Since: base-2.1 |
Defined in Text.Printf |
class HPrintfType t #
The HPrintfType
class provides the variable argument magic for
hPrintf
. Its implementation is intentionally not visible from
this module.
Minimal complete definition
hspr
Instances
a ~ () => HPrintfType (IO a) | Since: base-4.7.0.0 |
Defined in Text.Printf | |
(PrintfArg a, HPrintfType r) => HPrintfType (a -> r) | Since: base-2.1 |
Defined in Text.Printf |
Typeclass of printf
-formattable values. The formatArg
method
takes a value and a field format descriptor and either fails due
to a bad descriptor or produces a ShowS
as the result. The
default parseFormat
expects no modifiers: this is the normal
case. Minimal instance: formatArg
.
Minimal complete definition
Methods
formatArg :: a -> FieldFormatter #
Since: base-4.7.0.0
parseFormat :: a -> ModifierParser #
Since: base-4.7.0.0
Instances
PrintfArg Char | Since: base-2.1 |
Defined in Text.Printf | |
PrintfArg Double | Since: base-2.1 |
Defined in Text.Printf | |
PrintfArg Float | Since: base-2.1 |
Defined in Text.Printf | |
PrintfArg Int | Since: base-2.1 |
Defined in Text.Printf | |
PrintfArg Int8 | Since: base-2.1 |
Defined in Text.Printf | |
PrintfArg Int16 | Since: base-2.1 |
Defined in Text.Printf | |
PrintfArg Int32 | Since: base-2.1 |
Defined in Text.Printf | |
PrintfArg Int64 | Since: base-2.1 |
Defined in Text.Printf | |
PrintfArg Integer | Since: base-2.1 |
Defined in Text.Printf | |
PrintfArg Natural | Since: base-4.8.0.0 |
Defined in Text.Printf | |
PrintfArg Word | Since: base-2.1 |
Defined in Text.Printf | |
PrintfArg Word8 | Since: base-2.1 |
Defined in Text.Printf | |
PrintfArg Word16 | Since: base-2.1 |
Defined in Text.Printf | |
PrintfArg Word32 | Since: base-2.1 |
Defined in Text.Printf | |
PrintfArg Word64 | Since: base-2.1 |
Defined in Text.Printf | |
IsChar c => PrintfArg [c] | Since: base-2.1 |
Defined in Text.Printf |
data FormatAdjustment #
Whether to left-adjust or zero-pad a field. These are
mutually exclusive, with LeftAdjust
taking precedence.
Since: base-4.7.0.0
Constructors
LeftAdjust | |
ZeroPad |
data FormatSign #
How to handle the sign of a numeric field. These are
mutually exclusive, with SignPlus
taking precedence.
Since: base-4.7.0.0
data FieldFormat #
Description of field formatting for formatArg
. See UNIX printf(3)
for a description of how field formatting works.
Since: base-4.7.0.0
Constructors
FieldFormat | |
Fields
|
data FormatParse #
The "format parser" walks over argument-type-specific modifier characters to find the primary format character. This is the type of its result.
Since: base-4.7.0.0
Constructors
FormatParse | |
type FieldFormatter = FieldFormat -> ShowS #
This is the type of a field formatter reified over its argument.
Since: base-4.7.0.0
type ModifierParser = String -> FormatParse #
Type of a function that will parse modifier characters from the format string.
Since: base-4.7.0.0
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when
.
newtype AssertionFailed #
Constructors
AssertionFailed String |
Instances
Show AssertionFailed | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception Methods showsPrec :: Int -> AssertionFailed -> ShowS # show :: AssertionFailed -> String # showList :: [AssertionFailed] -> ShowS # | |
Exception AssertionFailed | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception Methods toException :: AssertionFailed -> SomeException # |
class (Typeable e, Show e) => Exception e where #
Any type that you wish to throw or catch as an exception must be an
instance of the Exception
class. The simplest case is a new exception
type directly below the root:
data MyException = ThisException | ThatException deriving Show instance Exception MyException
The default method definitions in the Exception
class do what we need
in this case. You can now throw and catch ThisException
and
ThatException
as exceptions:
*Main> throw ThisException `catch` \e -> putStrLn ("Caught " ++ show (e :: MyException)) Caught ThisException
In more complicated examples, you may wish to define a whole hierarchy of exceptions:
--------------------------------------------------------------------- -- Make the root exception type for all the exceptions in a compiler data SomeCompilerException = forall e . Exception e => SomeCompilerException e instance Show SomeCompilerException where show (SomeCompilerException e) = show e instance Exception SomeCompilerException compilerExceptionToException :: Exception e => e -> SomeException compilerExceptionToException = toException . SomeCompilerException compilerExceptionFromException :: Exception e => SomeException -> Maybe e compilerExceptionFromException x = do SomeCompilerException a <- fromException x cast a --------------------------------------------------------------------- -- Make a subhierarchy for exceptions in the frontend of the compiler data SomeFrontendException = forall e . Exception e => SomeFrontendException e instance Show SomeFrontendException where show (SomeFrontendException e) = show e instance Exception SomeFrontendException where toException = compilerExceptionToException fromException = compilerExceptionFromException frontendExceptionToException :: Exception e => e -> SomeException frontendExceptionToException = toException . SomeFrontendException frontendExceptionFromException :: Exception e => SomeException -> Maybe e frontendExceptionFromException x = do SomeFrontendException a <- fromException x cast a --------------------------------------------------------------------- -- Make an exception type for a particular frontend compiler exception data MismatchedParentheses = MismatchedParentheses deriving Show instance Exception MismatchedParentheses where toException = frontendExceptionToException fromException = frontendExceptionFromException
We can now catch a MismatchedParentheses
exception as
MismatchedParentheses
, SomeFrontendException
or
SomeCompilerException
, but not other types, e.g. IOException
:
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses)) Caught MismatchedParentheses *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException)) Caught MismatchedParentheses *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException)) Caught MismatchedParentheses *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: IOException)) *** Exception: MismatchedParentheses
Minimal complete definition
Nothing
Methods
toException :: e -> SomeException #
fromException :: SomeException -> Maybe e #
displayException :: e -> String #
Render this exception value in a human-friendly manner.
Default implementation:
.show
Since: base-4.8.0.0
Instances
fromJust :: HasCallStack => Maybe a -> a #
void :: Functor f => f a -> f () #
discards or ignores the result of evaluation, such
as the return value of an void
valueIO
action.
Using ApplicativeDo
: '
' can be understood as the
void
asdo
expression
do as pure ()
with an inferred Functor
constraint.
Examples
Replace the contents of a
with unit:Maybe
Int
>>>
void Nothing
Nothing>>>
void (Just 3)
Just ()
Replace the contents of an
with unit, resulting in an Either
Int
Int
:Either
Int
()
>>>
void (Left 8675309)
Left 8675309>>>
void (Right 8675309)
Right ()
Replace every element of a list with unit:
>>>
void [1,2,3]
[(),(),()]
Replace the second element of a pair with unit:
>>>
void (1,2)
(1,())
Discard the result of an IO
action:
>>>
mapM print [1,2]
1 2 [(),()]>>>
void $ mapM print [1,2]
1 2
An MVar
(pronounced "em-var") is a synchronising variable, used
for communication between concurrent threads. It can be thought of
as a box, which may be empty or full.
Instances
NFData1 MVar | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Eq (MVar a) | Since: base-4.1.0.0 |
NFData (MVar a) | NOTE: Only strict in the reference and not the referenced value. Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq |
when :: Applicative f => Bool -> f () -> f () #
Conditional execution of Applicative
expressions. For example,
when debug (putStrLn "Debugging")
will output the string Debugging
if the Boolean value debug
is True
, and otherwise do nothing.
data SomeException #
The SomeException
type is the root of the exception type hierarchy.
When an exception of type e
is thrown, behind the scenes it is
encapsulated in a SomeException
.
Constructors
Exception e => SomeException e |
Instances
Show SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type Methods showsPrec :: Int -> SomeException -> ShowS # show :: SomeException -> String # showList :: [SomeException] -> ShowS # | |
Exception SomeException | Since: base-3.0 |
Defined in GHC.Exception.Type Methods toException :: SomeException -> SomeException # fromException :: SomeException -> Maybe SomeException # displayException :: SomeException -> String # |
class MonadIO m => MonadUnliftIO (m :: Type -> Type) #
Monads which allow their actions to be run in IO
.
While MonadIO
allows an IO
action to be lifted into another
monad, this class captures the opposite concept: allowing you to
capture the monadic context. Note that, in order to meet the laws
given below, the intuition is that a monad must have no monadic
state, but may have monadic context. This essentially limits
MonadUnliftIO
to ReaderT
and IdentityT
transformers on top of
IO
.
Laws. For any value u
returned by askUnliftIO
, it must meet the
monad transformer laws as reformulated for MonadUnliftIO
:
unliftIO u . return = return
unliftIO u (m >>= f) = unliftIO u m >>= unliftIO u . f
Instances of MonadUnliftIO
must also satisfy the idempotency law:
askUnliftIO >>= \u -> (liftIO . unliftIO u) m = m
This law showcases two properties. First, askUnliftIO
doesn't change
the monadic context, and second, liftIO . unliftIO u
is equivalent to
id
IF called in the same monadic context as askUnliftIO
.
Since: unliftio-core-0.1.0.0
Minimal complete definition
Instances
MonadUnliftIO IO | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO m => MonadUnliftIO (ResourceT m) | Since: resourcet-1.1.10 |
Defined in Control.Monad.Trans.Resource.Internal | |
MonadUnliftIO m => MonadUnliftIO (NoLoggingT m) | Since: monad-logger-0.3.26 |
Defined in Control.Monad.Logger Methods withRunInIO :: ((forall a. NoLoggingT m a -> IO a) -> IO b) -> NoLoggingT m b # | |
MonadUnliftIO m => MonadUnliftIO (LoggingT m) | Since: monad-logger-0.3.26 |
Defined in Control.Monad.Logger | |
MonadUnliftIO m => MonadUnliftIO (ReaderT r m) | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO m => MonadUnliftIO (IdentityT m) | |
Defined in Control.Monad.IO.Unlift |
data ResourceT (m :: Type -> Type) a #
The Resource transformer. This transformer keeps track of all registered
actions, and calls them upon exit (via runResourceT
). Actions may be
registered via register
, or resources may be allocated atomically via
allocate
. allocate
corresponds closely to bracket
.
Releasing may be performed before exit via the release
function. This is a
highly recommended optimization, as it will ensure that scarce resources are
freed early. Note that calling release
will deregister the action, so that
a release action will only ever be called once.
Since 0.3.0
Instances
class MonadIO m => MonadResource (m :: Type -> Type) where #
A Monad
which allows for safe resource allocation. In theory, any monad
transformer stack which includes a ResourceT
can be an instance of
MonadResource
.
Note: runResourceT
has a requirement for a MonadUnliftIO m
monad,
which allows control operations to be lifted. A MonadResource
does not
have this requirement. This means that transformers such as ContT
can be
an instance of MonadResource
. However, the ContT
wrapper will need to be
unwrapped before calling runResourceT
.
Since 0.3.0
Methods
liftResourceT :: ResourceT IO a -> m a #
Lift a ResourceT IO
action into the current Monad
.
Since 0.4.0
Instances
runResourceT :: MonadUnliftIO m => ResourceT m a -> m a #
Unwrap a ResourceT
transformer, and call all registered release actions.
Note that there is some reference counting involved due to resourceForkIO
.
If multiple threads are sharing the same collection of resources, only the
last call to runResourceT
will deallocate the resources.
NOTE Since version 1.2.0, this function will throw a
ResourceCleanupException
if any of the cleanup functions throw an
exception.
Since: resourcet-0.3.0
class Monad m => MonadThrow (m :: Type -> Type) where #
A class for monads in which exceptions may be thrown.
Instances should obey the following law:
throwM e >> x = throwM e
In other words, throwing an exception short-circuits the rest of the monadic computation.
Methods
throwM :: Exception e => e -> m a #
Throw an exception. Note that this throws when this action is run in
the monad m
, not when it is applied. It is a generalization of
Control.Exception's throwIO
.
Should satisfy the law:
throwM e >> f = throwM e
Instances
bracketOnError :: MonadMask m => m a -> (a -> m c) -> (a -> m b) -> m b #
Like bracket
, but only performs the final action if an error is
thrown by the in-between computation.
finally :: MonadMask m => m a -> m b -> m a #
Perform an action with a finalizer action that is run, even if an error occurs.
bracket_ :: MonadMask m => m a -> m c -> m b -> m b #
Version of bracket
without any value being passed to the second and
third actions.
bracket :: MonadMask m => m a -> (a -> m c) -> (a -> m b) -> m b #
Generalized abstracted pattern of safe resource acquisition and release
in the face of errors. The first action "acquires" some value, which
is "released" by the second action at the end. The third action "uses"
the value and its result is the result of the bracket
.
If an error is thrown during the use, the release still happens before the error is rethrown.
Note that this is essentially a type-specialized version of
generalBracket
. This function has a more common signature (matching the
signature from Control.Exception), and is often more convenient to use. By
contrast, generalBracket
is more expressive, allowing us to implement
other functions like bracketOnError
.
onError :: MonadMask m => m a -> m b -> m a #
Run an action only if an error is thrown in the main action. Unlike
onException
, this works with every kind of error, not just exceptions. For
example, if f
is an ExceptT
computation which aborts with a Left
, the
computation onError f g
will execute g
, while onException f g
will not.
This distinction is only meaningful for monads which have multiple exit
points, such as Except
and MaybeT
. For monads that only have a single
exit point, there is no difference between onException
and onError
,
except that onError
has a more constrained type.
Since: exceptions-0.10.0
onException :: MonadCatch m => m a -> m b -> m a #
Run an action only if an exception is thrown in the main action. The exception is not caught, simply rethrown.
NOTE The action is only run if an exception is thrown. If the monad
supports other ways of aborting the computation, the action won't run if
those other kinds of errors are thrown. See onError
.
catches :: (Foldable f, MonadCatch m) => m a -> f (Handler m a) -> m a #
Catches different sorts of exceptions. See Control.Exception's catches
tryJust :: (MonadCatch m, Exception e) => (e -> Maybe b) -> m a -> m (Either b a) #
A variant of try
that takes an exception predicate to select
which exceptions are caught. See Control.Exception's tryJust
try :: (MonadCatch m, Exception e) => m a -> m (Either e a) #
Similar to catch
, but returns an Either
result. See Control.Exception's
try
.
handleJust :: (MonadCatch m, Exception e) => (e -> Maybe b) -> (b -> m a) -> m a -> m a #
Flipped catchJust
. See Control.Exception's handleJust
.
handleAll :: MonadCatch m => (SomeException -> m a) -> m a -> m a #
Flipped catchAll
handleIOError :: MonadCatch m => (IOError -> m a) -> m a -> m a #
Flipped catchIOError
handle :: (MonadCatch m, Exception e) => (e -> m a) -> m a -> m a #
Flipped catch
. See Control.Exception's handle
.
catchJust :: (MonadCatch m, Exception e) => (e -> Maybe b) -> m a -> (b -> m a) -> m a #
A more generalized way of determining which exceptions to catch at run time.
catchIf :: (MonadCatch m, Exception e) => (e -> Bool) -> m a -> (e -> m a) -> m a #
Catch exceptions only if they pass some predicate. Often useful with the
predicates for testing IOError
values in System.IO.Error.
catchIOError :: MonadCatch m => m a -> (IOError -> m a) -> m a #
Catch all IOError
(eqv. IOException
) exceptions. Still somewhat too
general, but better than using catchAll
. See catchIf
for an easy way
of catching specific IOError
s based on the predicates in System.IO.Error.
catchAll :: MonadCatch m => m a -> (SomeException -> m a) -> m a #
Catches all exceptions, and somewhat defeats the purpose of the extensible exception system. Use sparingly.
NOTE This catches all exceptions, but if the monad supports other ways of aborting the computation, those other kinds of errors will not be caught.
uninterruptibleMask_ :: MonadMask m => m a -> m a #
Like uninterruptibleMask
, but does not pass a restore
action to the
argument.
class MonadThrow m => MonadCatch (m :: Type -> Type) where #
A class for monads which allow exceptions to be caught, in particular
exceptions which were thrown by throwM
.
Instances should obey the following law:
catch (throwM e) f = f e
Note that the ability to catch an exception does not guarantee that we can
deal with all possible exit points from a computation. Some monads, such as
continuation-based stacks, allow for more than just a success/failure
strategy, and therefore catch
cannot be used by those monads to properly
implement a function such as finally
. For more information, see
MonadMask
.
Methods
catch :: Exception e => m a -> (e -> m a) -> m a #
Provide a handler for exceptions thrown during execution of the first
action. Note that type of the type of the argument to the handler will
constrain which exceptions are caught. See Control.Exception's
catch
.
Instances
class MonadCatch m => MonadMask (m :: Type -> Type) where #
A class for monads which provide for the ability to account for all possible exit points from a computation, and to mask asynchronous exceptions. Continuation-based monads are invalid instances of this class.
Instances should ensure that, in the following code:
fg = f `finally` g
The action g
is called regardless of what occurs within f
, including
async exceptions. Some monads allow f
to abort the computation via other
effects than throwing an exception. For simplicity, we will consider aborting
and throwing an exception to be two forms of "throwing an error".
If f
and g
both throw an error, the error thrown by fg
depends on which
errors we're talking about. In a monad transformer stack, the deeper layers
override the effects of the inner layers; for example, ExceptT e1 (Except
e2) a
represents a value of type Either e2 (Either e1 a)
, so throwing both
an e1
and an e2
will result in Left e2
. If f
and g
both throw an
error from the same layer, instances should ensure that the error from g
wins.
Effects other than throwing an error are also overriden by the deeper layers.
For example, StateT s Maybe a
represents a value of type s -> Maybe (a,
s)
, so if an error thrown from f
causes this function to return Nothing
,
any changes to the state which f
also performed will be erased. As a
result, g
will see the state as it was before f
. Once g
completes,
f
's error will be rethrown, so g
' state changes will be erased as well.
This is the normal interaction between effects in a monad transformer stack.
By contrast, lifted-base's
version of finally
always discards all of g
's non-IO effects, and g
never sees any of f
's non-IO effects, regardless of the layer ordering and
regardless of whether f
throws an error. This is not the result of
interacting effects, but a consequence of MonadBaseControl
's approach.
Methods
mask :: ((forall a. m a -> m a) -> m b) -> m b #
Runs an action with asynchronous exceptions disabled. The action is
provided a method for restoring the async. environment to what it was
at the mask
call. See Control.Exception's mask
.
uninterruptibleMask :: ((forall a. m a -> m a) -> m b) -> m b #
Like mask
, but the masked computation is not interruptible (see
Control.Exception's uninterruptibleMask
. WARNING:
Only use if you need to mask exceptions around an interruptible operation
AND you can guarantee the interruptible operation will only block for a
short period of time. Otherwise you render the program/thread unresponsive
and/or unkillable.
Arguments
:: m a | acquire some resource |
-> (a -> ExitCase b -> m c) | release the resource, observing the outcome of the inner action |
-> (a -> m b) | inner action to perform with the resource |
-> m (b, c) |
A generalized version of bracket
which uses ExitCase
to distinguish
the different exit cases, and returns the values of both the use
and
release
actions. In practice, this extra information is rarely needed,
so it is often more convenient to use one of the simpler functions which
are defined in terms of this one, such as bracket
, finally
, onError
,
and bracketOnError
.
This function exists because in order to thread their effects through the
execution of bracket
, monad transformers need values to be threaded from
use
to release
and from release
to the output value.
NOTE This method was added in version 0.9.0 of this
library. Previously, implementation of functions like bracket
and finally
in this module were based on the mask
and
uninterruptibleMask
functions only, disallowing some classes of
tranformers from having MonadMask
instances (notably
multi-exit-point transformers like ExceptT
). If you are a
library author, you'll now need to provide an implementation for
this method. The StateT
implementation demonstrates most of the
subtleties:
generalBracket acquire release use = StateT $ s0 -> do ((b, _s2), (c, s3)) <- generalBracket (runStateT acquire s0) ((resource, s1) exitCase -> case exitCase of ExitCaseSuccess (b, s2) -> runStateT (release resource (ExitCaseSuccess b)) s2 -- In the two other cases, the base monad overridesuse
's state -- changes and the state reverts tos1
. ExitCaseException e -> runStateT (release resource (ExitCaseException e)) s1 ExitCaseAbort -> runStateT (release resource ExitCaseAbort) s1 ) ((resource, s1) -> runStateT (use resource) s1) return ((b, c), s3)
The StateT s m
implementation of generalBracket
delegates to the m
implementation of generalBracket
. The acquire
, use
, and release
arguments given to StateT
's implementation produce actions of type
StateT s m a
, StateT s m b
, and StateT s m c
. In order to run those
actions in the base monad, we need to call runStateT
, from which we
obtain actions of type m (a, s)
, m (b, s)
, and m (c, s)
. Since each
action produces the next state, it is important to feed the state produced
by the previous action to the next action.
In the ExitCaseSuccess
case, the state starts at s0
, flows through
acquire
to become s1
, flows through use
to become s2
, and finally
flows through release
to become s3
. In the other two cases, release
does not receive the value s2
, so its action cannot see the state changes
performed by use
. This is fine, because in those two cases, an error was
thrown in the base monad, so as per the usual interaction between effects
in a monad transformer stack, those state changes get reverted. So we start
from s1
instead.
Finally, the m
implementation of generalBracket
returns the pairs
(b, s)
and (c, s)
. For monad transformers other than StateT
, this
will be some other type representing the effects and values performed and
returned by the use
and release
actions. The effect part of the use
result, in this case _s2
, usually needs to be discarded, since those
effects have already been incorporated in the release
action.
The only effect which is intentionally not incorporated in the release
action is the effect of throwing an error. In that case, the error must be
re-thrown. One subtlety which is easy to miss is that in the case in which
use
and release
both throw an error, the error from release
should
take priority. Here is an implementation for ExceptT
which demonstrates
how to do this.
generalBracket acquire release use = ExceptT $ do (eb, ec) <- generalBracket (runExceptT acquire) (eresource exitCase -> case eresource of Left e -> return (Left e) -- nothing to release, acquire didn't succeed Right resource -> case exitCase of ExitCaseSuccess (Right b) -> runExceptT (release resource (ExitCaseSuccess b)) ExitCaseException e -> runExceptT (release resource (ExitCaseException e)) _ -> runExceptT (release resource ExitCaseAbort)) (either (return . Left) (runExceptT . use)) return $ do -- The order in which we perform those twoEither
effects determines -- which error will win if they are bothLeft
s. We want the error from --release
to win. c <- ec b <- eb return (b, c)
Since: exceptions-0.9.0
Instances
MonadMask IO | |
e ~ SomeException => MonadMask (Either e) | Since: exceptions-0.8.3 |
Defined in Control.Monad.Catch | |
MonadMask m => MonadMask (MaybeT m) | Since: exceptions-0.10.0 |
Defined in Control.Monad.Catch | |
MonadMask m => MonadMask (ResourceT m) | |
Defined in Control.Monad.Trans.Resource.Internal Methods mask :: ((forall a. ResourceT m a -> ResourceT m a) -> ResourceT m b) -> ResourceT m b # uninterruptibleMask :: ((forall a. ResourceT m a -> ResourceT m a) -> ResourceT m b) -> ResourceT m b # generalBracket :: ResourceT m a -> (a -> ExitCase b -> ResourceT m c) -> (a -> ResourceT m b) -> ResourceT m (b, c) # | |
MonadMask m => MonadMask (NoLoggingT m) | |
Defined in Control.Monad.Logger Methods mask :: ((forall a. NoLoggingT m a -> NoLoggingT m a) -> NoLoggingT m b) -> NoLoggingT m b # uninterruptibleMask :: ((forall a. NoLoggingT m a -> NoLoggingT m a) -> NoLoggingT m b) -> NoLoggingT m b # generalBracket :: NoLoggingT m a -> (a -> ExitCase b -> NoLoggingT m c) -> (a -> NoLoggingT m b) -> NoLoggingT m (b, c) # | |
MonadMask m => MonadMask (WriterLoggingT m) | |
Defined in Control.Monad.Logger Methods mask :: ((forall a. WriterLoggingT m a -> WriterLoggingT m a) -> WriterLoggingT m b) -> WriterLoggingT m b # uninterruptibleMask :: ((forall a. WriterLoggingT m a -> WriterLoggingT m a) -> WriterLoggingT m b) -> WriterLoggingT m b # generalBracket :: WriterLoggingT m a -> (a -> ExitCase b -> WriterLoggingT m c) -> (a -> WriterLoggingT m b) -> WriterLoggingT m (b, c) # | |
MonadMask m => MonadMask (LoggingT m) | |
Defined in Control.Monad.Logger Methods mask :: ((forall a. LoggingT m a -> LoggingT m a) -> LoggingT m b) -> LoggingT m b # uninterruptibleMask :: ((forall a. LoggingT m a -> LoggingT m a) -> LoggingT m b) -> LoggingT m b # generalBracket :: LoggingT m a -> (a -> ExitCase b -> LoggingT m c) -> (a -> LoggingT m b) -> LoggingT m (b, c) # | |
MonadMask m => MonadMask (NodeT m) Source # | |
Defined in Foreign.Erlang.LocalNode | |
(MonadMask m, Monoid w) => MonadMask (WriterT w m) | |
Defined in Control.Monad.Catch Methods mask :: ((forall a. WriterT w m a -> WriterT w m a) -> WriterT w m b) -> WriterT w m b # uninterruptibleMask :: ((forall a. WriterT w m a -> WriterT w m a) -> WriterT w m b) -> WriterT w m b # generalBracket :: WriterT w m a -> (a -> ExitCase b -> WriterT w m c) -> (a -> WriterT w m b) -> WriterT w m (b, c) # | |
(MonadMask m, Monoid w) => MonadMask (WriterT w m) | |
Defined in Control.Monad.Catch Methods mask :: ((forall a. WriterT w m a -> WriterT w m a) -> WriterT w m b) -> WriterT w m b # uninterruptibleMask :: ((forall a. WriterT w m a -> WriterT w m a) -> WriterT w m b) -> WriterT w m b # generalBracket :: WriterT w m a -> (a -> ExitCase b -> WriterT w m c) -> (a -> WriterT w m b) -> WriterT w m (b, c) # | |
MonadMask m => MonadMask (StateT s m) | |
Defined in Control.Monad.Catch Methods mask :: ((forall a. StateT s m a -> StateT s m a) -> StateT s m b) -> StateT s m b # uninterruptibleMask :: ((forall a. StateT s m a -> StateT s m a) -> StateT s m b) -> StateT s m b # generalBracket :: StateT s m a -> (a -> ExitCase b -> StateT s m c) -> (a -> StateT s m b) -> StateT s m (b, c) # | |
MonadMask m => MonadMask (StateT s m) | |
Defined in Control.Monad.Catch Methods mask :: ((forall a. StateT s m a -> StateT s m a) -> StateT s m b) -> StateT s m b # uninterruptibleMask :: ((forall a. StateT s m a -> StateT s m a) -> StateT s m b) -> StateT s m b # generalBracket :: StateT s m a -> (a -> ExitCase b -> StateT s m c) -> (a -> StateT s m b) -> StateT s m (b, c) # | |
MonadMask m => MonadMask (ReaderT r m) | |
Defined in Control.Monad.Catch Methods mask :: ((forall a. ReaderT r m a -> ReaderT r m a) -> ReaderT r m b) -> ReaderT r m b # uninterruptibleMask :: ((forall a. ReaderT r m a -> ReaderT r m a) -> ReaderT r m b) -> ReaderT r m b # generalBracket :: ReaderT r m a -> (a -> ExitCase b -> ReaderT r m c) -> (a -> ReaderT r m b) -> ReaderT r m (b, c) # | |
MonadMask m => MonadMask (ExceptT e m) | Since: exceptions-0.9.0 |
Defined in Control.Monad.Catch Methods mask :: ((forall a. ExceptT e m a -> ExceptT e m a) -> ExceptT e m b) -> ExceptT e m b # uninterruptibleMask :: ((forall a. ExceptT e m a -> ExceptT e m a) -> ExceptT e m b) -> ExceptT e m b # generalBracket :: ExceptT e m a -> (a -> ExitCase b -> ExceptT e m c) -> (a -> ExceptT e m b) -> ExceptT e m (b, c) # | |
(Error e, MonadMask m) => MonadMask (ErrorT e m) | |
Defined in Control.Monad.Catch Methods mask :: ((forall a. ErrorT e m a -> ErrorT e m a) -> ErrorT e m b) -> ErrorT e m b # uninterruptibleMask :: ((forall a. ErrorT e m a -> ErrorT e m a) -> ErrorT e m b) -> ErrorT e m b # generalBracket :: ErrorT e m a -> (a -> ExitCase b -> ErrorT e m c) -> (a -> ErrorT e m b) -> ErrorT e m (b, c) # | |
MonadMask m => MonadMask (IdentityT m) | |
Defined in Control.Monad.Catch Methods mask :: ((forall a. IdentityT m a -> IdentityT m a) -> IdentityT m b) -> IdentityT m b # uninterruptibleMask :: ((forall a. IdentityT m a -> IdentityT m a) -> IdentityT m b) -> IdentityT m b # generalBracket :: IdentityT m a -> (a -> ExitCase b -> IdentityT m c) -> (a -> IdentityT m b) -> IdentityT m (b, c) # | |
(MonadMask m, Monoid w) => MonadMask (RWST r w s m) | |
Defined in Control.Monad.Catch Methods mask :: ((forall a. RWST r w s m a -> RWST r w s m a) -> RWST r w s m b) -> RWST r w s m b # uninterruptibleMask :: ((forall a. RWST r w s m a -> RWST r w s m a) -> RWST r w s m b) -> RWST r w s m b # generalBracket :: RWST r w s m a -> (a -> ExitCase b -> RWST r w s m c) -> (a -> RWST r w s m b) -> RWST r w s m (b, c) # | |
(MonadMask m, Monoid w) => MonadMask (RWST r w s m) | |
Defined in Control.Monad.Catch Methods mask :: ((forall a. RWST r w s m a -> RWST r w s m a) -> RWST r w s m b) -> RWST r w s m b # uninterruptibleMask :: ((forall a. RWST r w s m a -> RWST r w s m a) -> RWST r w s m b) -> RWST r w s m b # generalBracket :: RWST r w s m a -> (a -> ExitCase b -> RWST r w s m c) -> (a -> RWST r w s m b) -> RWST r w s m (b, c) # |
A MonadMask
computation may either succeed with a value, abort with an
exception, or abort for some other reason. For example, in ExceptT e IO
you can use throwM
to abort with an exception (ExitCaseException
) or
throwE
to abort with a value of type e
(ExitCaseAbort
).
Constructors
ExitCaseSuccess a | |
ExitCaseException SomeException | |
ExitCaseAbort |
type family StM (m :: Type -> Type) a #
Monadic state that m
adds to the base monad b
.
For all base (non-transformed) monads, StM m a ~ a
:
StMIO
a ~ a StMMaybe
a ~ a StM (Either
e) a ~ a StM [] a ~ a StM ((->) r) a ~ a StMIdentity
a ~ a StMSTM
a ~ a StM (ST
s) a ~ a
If m
is a transformed monad, m ~ t b
,
is the monadic state of
the transformer StM
t
(given by its StT
from MonadTransControl
). For a
transformer stack,
is defined recursively:StM
StM (IdentityT
m) a ~ComposeSt
IdentityT
m a ~ StM m a StM (MaybeT
m) a ~ComposeSt
MaybeT
m a ~ StM m (Maybe
a) StM (ErrorT
e m) a ~ComposeSt
ErrorT
m a ~Error
e => StM m (Either
e a) StM (ExceptT
e m) a ~ComposeSt
ExceptT
m a ~ StM m (Either
e a) StM (ListT
m) a ~ComposeSt
ListT
m a ~ StM m [a] StM (ReaderT
r m) a ~ComposeSt
ReaderT
m a ~ StM m a StM (StateT
s m) a ~ComposeSt
StateT
m a ~ StM m (a, s) StM (WriterT
w m) a ~ComposeSt
WriterT
m a ~Monoid
w => StM m (a, w) StM (RWST
r w s m) a ~ComposeSt
RWST
m a ~Monoid
w => StM m (a, s, w)
Instances
replicateConcurrently_ :: MonadBaseControl IO m => Int -> m a -> m () #
Generalized version of replicateConcurrently_
.
replicateConcurrently :: MonadBaseControl IO m => Int -> m a -> m [a] #
Generalized version of replicateConcurrently
.
forConcurrently_ :: (Foldable t, MonadBaseControl IO m) => t a -> (a -> m b) -> m () #
Generalized version of forConcurrently_
.
forConcurrently :: (Traversable t, MonadBaseControl IO m) => t a -> (a -> m b) -> m (t b) #
Generalized version of forConcurrently
.
mapConcurrently_ :: (Foldable t, MonadBaseControl IO m) => (a -> m b) -> t a -> m () #
Generalized version of mapConcurrently_
.
mapConcurrently :: (Traversable t, MonadBaseControl IO m) => (a -> m b) -> t a -> m (t b) #
Generalized version of mapConcurrently
.
concurrently_ :: MonadBaseControl IO m => m a -> m b -> m () #
Generalized version of concurrently_
.
concurrently :: MonadBaseControl IO m => m a -> m b -> m (a, b) #
Generalized version of concurrently
.
race_ :: MonadBaseControl IO m => m a -> m b -> m () #
Generalized version of race_
.
NOTE: This function discards the monadic effects besides IO in the forked computation.
waitBoth :: MonadBaseControl IO m => Async (StM m a) -> Async (StM m b) -> m (a, b) #
Generalized version of waitBoth
.
waitEither_ :: MonadBase IO m => Async a -> Async b -> m () #
Generalized version of waitEither_
.
NOTE: This function discards the monadic effects besides IO in the forked computation.
waitEitherCatchCancel :: MonadBaseControl IO m => Async (StM m a) -> Async (StM m b) -> m (Either (Either SomeException a) (Either SomeException b)) #
Generalized version of waitEitherCatchCancel
.
waitEitherCancel :: MonadBaseControl IO m => Async (StM m a) -> Async (StM m b) -> m (Either a b) #
Generalized version of waitEitherCancel
.
waitEitherCatch :: MonadBaseControl IO m => Async (StM m a) -> Async (StM m b) -> m (Either (Either SomeException a) (Either SomeException b)) #
Generalized version of waitEitherCatch
.
waitEither :: MonadBaseControl IO m => Async (StM m a) -> Async (StM m b) -> m (Either a b) #
Generalized version of waitEither
.
waitAnyCatchCancel :: MonadBaseControl IO m => [Async (StM m a)] -> m (Async (StM m a), Either SomeException a) #
Generalized version of waitAnyCatchCancel
.
waitAnyCancel :: MonadBaseControl IO m => [Async (StM m a)] -> m (Async (StM m a), a) #
Generalized version of waitAnyCancel
.
waitAnyCatch :: MonadBaseControl IO m => [Async (StM m a)] -> m (Async (StM m a), Either SomeException a) #
Generalized version of waitAnyCatch
.
waitAny :: MonadBaseControl IO m => [Async (StM m a)] -> m (Async (StM m a), a) #
Generalized version of waitAny
.
waitCatch :: MonadBaseControl IO m => Async (StM m a) -> m (Either SomeException a) #
Generalized version of waitCatch
.
uninterruptibleCancel :: MonadBase IO m => Async a -> m () #
Generalized version of uninterruptibleCancel
.
cancelWith :: (MonadBase IO m, Exception e) => Async a -> e -> m () #
Generalized version of cancelWith
.
poll :: MonadBaseControl IO m => Async (StM m a) -> m (Maybe (Either SomeException a)) #
Generalized version of poll
.
withAsyncOnWithUnmask :: MonadBaseControl IO m => Int -> ((forall c. m c -> m c) -> m a) -> (Async (StM m a) -> m b) -> m b #
Generalized version of withAsyncOnWithUnmask
.
withAsyncWithUnmask :: MonadBaseControl IO m => ((forall c. m c -> m c) -> m a) -> (Async (StM m a) -> m b) -> m b #
Generalized version of withAsyncWithUnmask
.
withAsyncOn :: MonadBaseControl IO m => Int -> m a -> (Async (StM m a) -> m b) -> m b #
Generalized version of withAsyncOn
.
withAsyncBound :: MonadBaseControl IO m => m a -> (Async (StM m a) -> m b) -> m b #
Generalized version of withAsyncBound
.
withAsync :: MonadBaseControl IO m => m a -> (Async (StM m a) -> m b) -> m b #
Generalized version of withAsync
.
asyncOnWithUnmask :: MonadBaseControl IO m => Int -> ((forall b. m b -> m b) -> m a) -> m (Async (StM m a)) #
Generalized version of asyncOnWithUnmask
.
asyncWithUnmask :: MonadBaseControl IO m => ((forall b. m b -> m b) -> m a) -> m (Async (StM m a)) #
Generalized version of asyncWithUnmask
.
asyncOn :: MonadBaseControl IO m => Int -> m a -> m (Async (StM m a)) #
Generalized version of asyncOn
.
asyncBound :: MonadBaseControl IO m => m a -> m (Async (StM m a)) #
Generalized version of asyncBound
.
newtype Concurrently (m :: Type -> Type) a #
Generalized version of Concurrently
.
A value of type
is an IO-based operation that can be
composed with other Concurrently
m aConcurrently
values, using the Applicative
and
Alternative
instances.
Calling runConcurrently
on a value of type
will
execute the IO-based lifted operations it contains concurrently, before
delivering the result of type Concurrently
m aa
.
For example
(page1, page2, page3) <-runConcurrently
$ (,,)<$>
Concurrently
(getURL "url1")<*>
Concurrently
(getURL "url2")<*>
Concurrently
(getURL "url3")
Constructors
Concurrently | |
Fields
|
Instances
liftBaseOp_ :: MonadBaseControl b m => (b (StM m a) -> b (StM m c)) -> m a -> m c #
liftBaseOp_
is a particular application of liftBaseWith
that allows
lifting control operations of type:
(b a -> b a)
to:
(MonadBaseControl
b m => m a -> m a)
For example:
liftBaseOp_ mask_ ::MonadBaseControl
IO
m => m a -> m a
mkWeakThreadId :: MonadBase IO m => ThreadId -> m (Weak ThreadId) #
Generalized versio of mkWeakThreadId
.
runInUnboundThread :: MonadBaseControl IO m => m a -> m a #
Generalized version of runInUnboundThread
.
runInBoundThread :: MonadBaseControl IO m => m a -> m a #
Generalized version of runInBoundThread
.
isCurrentThreadBound :: MonadBase IO m => m Bool #
Generalized version of isCurrentThreadBound
.
forkOS :: MonadBaseControl IO m => m () -> m ThreadId #
threadWaitWrite :: MonadBase IO m => Fd -> m () #
Generalized version of threadWaitWrite
.
threadWaitRead :: MonadBase IO m => Fd -> m () #
Generalized version of threadWaitRead
.
threadDelay :: MonadBase IO m => Int -> m () #
Generalized version of threadDelay
.
threadCapability :: MonadBase IO m => ThreadId -> m (Int, Bool) #
Generalized version of threadCapability
.
setNumCapabilities :: MonadBase IO m => Int -> m () #
Generalized version of setNumCapabilities
.
getNumCapabilities :: MonadBase IO m => m Int #
Generalized version of getNumCapabilities
.
forkOnWithUnmask :: MonadBaseControl IO m => Int -> ((forall a. m a -> m a) -> m ()) -> m ThreadId #
Generalized version of forkOnWithUnmask
.
Note that, while the forked computation m ()
has access to the captured
state, all its side-effects in m
are discarded. It is run only for its
side-effects in IO
.
killThread :: MonadBase IO m => ThreadId -> m () #
Generalized version of killThread
.
forkFinally :: MonadBaseControl IO m => m a -> (Either SomeException a -> m ()) -> m ThreadId #
Generalized version of forkFinally
.
Note that in forkFinally action and_then
, while the forked
action
and the and_then
function have access to the captured
state, all their side-effects in m
are discarded. They're run
only for their side-effects in IO
.
forkWithUnmask :: MonadBaseControl IO m => ((forall a. m a -> m a) -> m ()) -> m ThreadId #
Generalized version of forkIOWithUnmask
.
Note that, while the forked computation m ()
has access to the captured
state, all its side-effects in m
are discarded. It is run only for its
side-effects in IO
.
fork :: MonadBaseControl IO m => m () -> m ThreadId #
myThreadId :: MonadBase IO m => m ThreadId #
Generalized version of myThreadId
.
signalQSemN :: MonadBase IO m => QSemN -> Int -> m () #
Generalized version of signalQSemN
.
signalQSem :: MonadBase IO m => QSem -> m () #
Generalized version of signalQSem
.
tryReadMVar :: MonadBase IO m => MVar a -> m (Maybe a) #
Generalized version of tryReadMVar
.
withMVarMasked :: MonadBaseControl IO m => MVar a -> (a -> m b) -> m b #
Generalized version of withMVarMasked
.
mkWeakMVar :: MonadBaseControl IO m => MVar a -> m () -> m (Weak (MVar a)) #
Generalized version of mkWeakMVar
.
Note any monadic side effects in m
of the "finalizer" computation are
discarded.
modifyMVarMasked :: MonadBaseControl IO m => MVar a -> (a -> m (a, b)) -> m b #
Generalized version of modifyMVarMasked
.
modifyMVarMasked_ :: MonadBaseControl IO m => MVar a -> (a -> m a) -> m () #
Generalized version of modifyMVarMasked_
.
modifyMVar :: MonadBaseControl IO m => MVar a -> (a -> m (a, b)) -> m b #
Generalized version of modifyMVar
.
modifyMVar_ :: MonadBaseControl IO m => MVar a -> (a -> m a) -> m () #
Generalized version of modifyMVar_
.
isEmptyMVar :: MonadBase IO m => MVar a -> m Bool #
Generalized version of isEmptyMVar
.
tryPutMVar :: MonadBase IO m => MVar a -> a -> m Bool #
Generalized version of tryPutMVar
.
tryTakeMVar :: MonadBase IO m => MVar a -> m (Maybe a) #
Generalized version of tryTakeMVar
.
newEmptyMVar :: MonadBase IO m => m (MVar a) #
Generalized version of newEmptyMVar
.
writeList2Chan :: MonadBase IO m => Chan a -> [a] -> m () #
Generalized version of writeList2Chan
.
getChanContents :: MonadBase IO m => Chan a -> m [a] #
Generalized version of getChanContents
.
Arguments
:: (MonadTransControl t, Monad (t m), Monad m) | |
=> (m (StT t a) -> m (StT t b)) | |
-> t m a | |
-> t m b |
Transform an action in t m
using a transformer that operates on the underlying monad m
liftBaseOpDiscard :: MonadBaseControl b m => ((a -> b ()) -> b c) -> (a -> m ()) -> m c #
liftBaseOpDiscard
is a particular application of liftBaseWith
that allows
lifting control operations of type:
((a -> b ()) -> b c)
to:
(MonadBaseControl
b m => (a -> m ()) -> m c)
Note that, while the argument computation m ()
has access to the captured
state, all its side-effects in m
are discarded. It is run only for its
side-effects in the base monad b
.
For example:
liftBaseDiscard (runServer addr port) ::MonadBaseControl
IO
m => m () -> m ()
liftBaseDiscard :: MonadBaseControl b m => (b () -> b a) -> m () -> m a #
liftBaseDiscard
is a particular application of liftBaseWith
that allows
lifting control operations of type:
(b () -> b a)
to:
(MonadBaseControl
b m => m () -> m a)
Note that, while the argument computation m ()
has access to the captured
state, all its side-effects in m
are discarded. It is run only for its
side-effects in the base monad b
.
For example:
liftBaseDiscard forkIO ::MonadBaseControl
IO
m => m () -> m ThreadId
liftBaseOp :: MonadBaseControl b m => ((a -> b (StM m c)) -> b (StM m d)) -> (a -> m c) -> m d #
liftBaseOp
is a particular application of liftBaseWith
that allows
lifting control operations of type:
((a -> b c) -> b c)
to:
(MonadBaseControl
b m => (a -> m c) -> m c)
For example:
liftBaseOp alloca :: (Storable a,MonadBaseControl
IO
m) => (Ptr a -> m c) -> m c
captureM :: forall (b :: Type -> Type) m. MonadBaseControl b m => m (StM m ()) #
Capture the current state above the base monad
captureT :: forall t (m :: Type -> Type). (MonadTransControl t, Monad (t m), Monad m) => t m (StT t ()) #
Capture the current state of a transformer
embed_ :: MonadBaseControl b m => (a -> m ()) -> m (a -> b ()) #
Performs the same function as embed
, but discards transformer state
from the embedded function.
embed :: MonadBaseControl b m => (a -> m c) -> m (a -> b (StM m c)) #
Embed a transformer function as an function in the base monad returning a mutated transformer state.
control :: MonadBaseControl b m => (RunInBase m b -> b (StM m a)) -> m a #
An often used composition: control f =
liftBaseWith
f >>= restoreM
Example:
liftedBracket :: MonadBaseControl IO m => m a -> (a -> m b) -> (a -> m c) -> m c liftedBracket acquire release action = control $ \runInBase -> bracket (runInBase acquire) (\saved -> runInBase (restoreM saved >>= release)) (\saved -> runInBase (restoreM saved >>= action))
defaultRestoreM :: forall t (b :: Type -> Type) (m :: Type -> Type) a. (MonadTransControl t, MonadBaseControl b m) => ComposeSt t m a -> t m a #
defaultLiftBaseWith :: forall t b (m :: Type -> Type) a. (MonadTransControl t, MonadBaseControl b m) => (RunInBaseDefault t m b -> b a) -> t m a #
Default definition for the liftBaseWith
method.
Note that it composes a liftWith
of t
with a liftBaseWith
of m
to
give a liftBaseWith
of t m
:
defaultLiftBaseWith = \f ->liftWith
$ \run ->liftBaseWith
$ \runInBase -> f $ runInBase . run
Arguments
:: forall m (n' :: (Type -> Type) -> Type -> Type) n a t. (Monad m, Monad (n' m), MonadTransControl n, MonadTransControl n') | |
=> (n (n' m) a -> t m a) | Monad constructor |
-> m (StT n' (StT n a)) | |
-> t m a |
Default definition for the restoreT
method for double MonadTransControl
.
Arguments
:: forall m (n' :: (Type -> Type) -> Type -> Type) n t a. (Monad m, Monad (n' m), MonadTransControl n, MonadTransControl n') | |
=> (forall b. n (n' m) b -> t m b) | Monad constructor |
-> (forall (o :: Type -> Type) b. t o b -> n (n' o) b) | Monad deconstructor |
-> (RunDefault2 t n n' -> m a) | |
-> t m a |
Default definition for the liftWith
method.
Arguments
:: (Monad m, MonadTransControl n) | |
=> (n m a -> t m a) | Monad constructor |
-> m (StT n a) | |
-> t m a |
Default definition for the restoreT
method.
Arguments
:: (Monad m, MonadTransControl n) | |
=> (forall b. n m b -> t m b) | Monad constructor |
-> (forall (o :: Type -> Type) b. t o b -> n o b) | Monad deconstructor |
-> (RunDefault t n -> m a) | |
-> t m a |
Default definition for the liftWith
method.
type family StT (t :: (Type -> Type) -> Type -> Type) a #
Monadic state of t
.
The monadic state of a monad transformer is the result type of its run
function, e.g.:
runReaderT
::ReaderT
r m a -> r -> m aStT
(ReaderT
r) a ~ arunStateT
::StateT
s m a -> s -> m (a, s)StT
(StateT
s) a ~ (a, s)runMaybeT
::MaybeT
m a -> m (Maybe
a)StT
MaybeT
a ~Maybe
a
Provided type instances:
StTIdentityT
a ~ a StTMaybeT
a ~Maybe
a StT (ErrorT
e) a ~Error
e =>Either
e a StT (ExceptT
e) a ~Either
e a StTListT
a ~ [a] StT (ReaderT
r) a ~ a StT (StateT
s) a ~ (a, s) StT (WriterT
w) a ~Monoid
w => (a, w) StT (RWST
r w s) a ~Monoid
w => (a, s, w)
Instances
type StT MaybeT a | |
Defined in Control.Monad.Trans.Control | |
type StT ListT a | |
Defined in Control.Monad.Trans.Control | |
type StT NoLoggingT a | |
Defined in Control.Monad.Logger | |
type StT WriterLoggingT a | |
Defined in Control.Monad.Logger | |
type StT LoggingT a | |
Defined in Control.Monad.Logger | |
type StT (WriterT w) a | |
Defined in Control.Monad.Trans.Control | |
type StT (WriterT w) a | |
Defined in Control.Monad.Trans.Control | |
type StT (StateT s) a | |
Defined in Control.Monad.Trans.Control | |
type StT (StateT s) a | |
Defined in Control.Monad.Trans.Control | |
type StT (ReaderT r) a | |
Defined in Control.Monad.Trans.Control | |
type StT (ExceptT e) a | |
Defined in Control.Monad.Trans.Control | |
type StT (ErrorT e) a | |
Defined in Control.Monad.Trans.Control | |
type StT (IdentityT :: (Type -> Type) -> Type -> Type) a | |
type StT (RWST r w s) a | |
Defined in Control.Monad.Trans.Control | |
type StT (RWST r w s) a | |
Defined in Control.Monad.Trans.Control |
class MonadTrans t => MonadTransControl (t :: (Type -> Type) -> Type -> Type) where #
The MonadTransControl
type class is a stronger version of
:MonadTrans
Instances of
know how to MonadTrans
actions in the base monad to
the transformed monad. These lifted actions, however, are completely unaware
of the monadic state added by the transformer.lift
instances are aware of the monadic state of the
transformer and allow to save and restore this state.MonadTransControl
This allows to lift functions that have a monad transformer in both positive and negative position. Take, for example, the function
withFile :: FilePath -> IOMode -> (Handle -> IO r) -> IO r
instances can only lift the return type of the MonadTrans
withFile
function:
withFileLifted :: MonadTrans t => FilePath -> IOMode -> (Handle -> IO r) -> t IO r withFileLifted file mode action = lift (withFile file mode action)
However,
is not powerful enough to make MonadTrans
withFileLifted
accept a function that returns t IO
. The reason is that we need to take
away the transformer layer in order to pass the function to
.
withFile
allows us to do this:MonadTransControl
withFileLifted' :: (Monad (t IO), MonadTransControl t) => FilePath -> IOMode -> (Handle -> t IO r) -> t IO r withFileLifted' file mode action = liftWith (\run -> withFile file mode (run . action)) >>= restoreT . return
Associated Types
type StT (t :: (Type -> Type) -> Type -> Type) a #
Monadic state of t
.
The monadic state of a monad transformer is the result type of its run
function, e.g.:
runReaderT
::ReaderT
r m a -> r -> m aStT
(ReaderT
r) a ~ arunStateT
::StateT
s m a -> s -> m (a, s)StT
(StateT
s) a ~ (a, s)runMaybeT
::MaybeT
m a -> m (Maybe
a)StT
MaybeT
a ~Maybe
a
Provided type instances:
StTIdentityT
a ~ a StTMaybeT
a ~Maybe
a StT (ErrorT
e) a ~Error
e =>Either
e a StT (ExceptT
e) a ~Either
e a StTListT
a ~ [a] StT (ReaderT
r) a ~ a StT (StateT
s) a ~ (a, s) StT (WriterT
w) a ~Monoid
w => (a, w) StT (RWST
r w s) a ~Monoid
w => (a, s, w)
Methods
liftWith :: Monad m => (Run t -> m a) -> t m a #
liftWith
is similar to lift
in that it lifts a computation from
the argument monad to the constructed monad.
Instances should satisfy similar laws as the MonadTrans
laws:
liftWith . const . return = return
liftWith (const (m >>= f)) = liftWith (const m) >>= liftWith . const . f
The difference with lift
is that before lifting the m
computation
liftWith
captures the state of t
. It then provides the m
computation with a Run
function that allows running t n
computations in
n
(for all n
) on the captured state, e.g.
withFileLifted :: (Monad (t IO), MonadTransControl t) => FilePath -> IOMode -> (Handle -> t IO r) -> t IO r withFileLifted file mode action = liftWith (\run -> withFile file mode (run . action)) >>= restoreT . return
If the Run
function is ignored, liftWith
coincides with lift
:
lift f = liftWith (const f)
Implementations use the
function associated with a transformer:Run
liftWith ::Monad
m => ((Monad
n =>ReaderT
r n b -> n b) -> m a) ->ReaderT
r m a liftWith f =ReaderT
(r -> f (action ->runReaderT
action r)) liftWith ::Monad
m => ((Monad
n =>StateT
s n b -> n (b, s)) -> m a) ->StateT
s m a liftWith f =StateT
(s ->liftM
(x -> (x, s)) (f (action ->runStateT
action s))) liftWith ::Monad
m => ((Monad
n =>MaybeT
n b -> n (Maybe
b)) -> m a) ->MaybeT
m a liftWith f =MaybeT
(liftM
Just
(frunMaybeT
))
restoreT :: Monad m => m (StT t a) -> t m a #
Construct a t
computation from the monadic state of t
that is
returned from a Run
function.
Instances should satisfy:
liftWith (\run -> run t) >>= restoreT . return = t
restoreT
is usually implemented through the constructor of the monad
transformer:
ReaderT
:: (r -> m a) ->ReaderT
r m a restoreT :: m a ->ReaderT
r m a restoreT action =ReaderT
{ runReaderT =const
action }StateT
:: (s -> m (a, s)) ->StateT
s m a restoreT :: m (a, s) ->StateT
s m a restoreT action =StateT
{ runStateT =const
action }MaybeT
:: m (Maybe
a) ->MaybeT
m a restoreT :: m (Maybe
a) ->MaybeT
m a restoreT action =MaybeT
action
Example type signatures:
restoreT ::Monad
m => m a ->IdentityT
m a restoreT ::Monad
m => m (Maybe
a) ->MaybeT
m a restoreT :: (Monad
m,Error
e) => m (Either
e a) ->ErrorT
e m a restoreT ::Monad
m => m (Either
e a) ->ExceptT
e m a restoreT ::Monad
m => m [a] ->ListT
m a restoreT ::Monad
m => m a ->ReaderT
r m a restoreT ::Monad
m => m (a, s) ->StateT
s m a restoreT :: (Monad
m,Monoid
w) => m (a, w) ->WriterT
w m a restoreT :: (Monad
m,Monoid
w) => m (a, s, w) ->RWST
r w s m a
Instances
MonadTransControl MaybeT | |
MonadTransControl ListT | |
MonadTransControl NoLoggingT | |
Defined in Control.Monad.Logger Associated Types type StT NoLoggingT a # Methods liftWith :: Monad m => (Run NoLoggingT -> m a) -> NoLoggingT m a # restoreT :: Monad m => m (StT NoLoggingT a) -> NoLoggingT m a # | |
MonadTransControl WriterLoggingT | |
Defined in Control.Monad.Logger Associated Types type StT WriterLoggingT a # Methods liftWith :: Monad m => (Run WriterLoggingT -> m a) -> WriterLoggingT m a # restoreT :: Monad m => m (StT WriterLoggingT a) -> WriterLoggingT m a # | |
MonadTransControl LoggingT | |
Monoid w => MonadTransControl (WriterT w) | |
Monoid w => MonadTransControl (WriterT w) | |
MonadTransControl (StateT s) | |
MonadTransControl (StateT s) | |
MonadTransControl (ReaderT r) | |
MonadTransControl (ExceptT e) | |
Error e => MonadTransControl (ErrorT e) | |
MonadTransControl (IdentityT :: (Type -> Type) -> Type -> Type) | |
Monoid w => MonadTransControl (RWST r w s) | |
Monoid w => MonadTransControl (RWST r w s) | |
type Run (t :: (Type -> Type) -> Type -> Type) = forall (n :: Type -> Type) b. Monad n => t n b -> n (StT t b) #
A function that runs a transformed monad t n
on the monadic state that
was captured by liftWith
A Run t
function yields a computation in n
that returns the monadic state
of t
. This state can later be used to restore a t
computation using
restoreT
.
Example type equalities:
RunIdentityT
~ forall n b.Monad
n =>IdentityT
n b -> n b RunMaybeT
~ forall n b.Monad
n =>MaybeT
n b -> n (Maybe
b) Run (ErrorT
e) ~ forall n b. (Monad
n,Error
e) =>ErrorT
e n b -> n (Either
e b) Run (ExceptT
e) ~ forall n b.Monad
n =>ExceptT
e n b -> n (Either
e b) RunListT
~ forall n b.Monad
n =>ListT
n b -> n [b] Run (ReaderT
r) ~ forall n b.Monad
n =>ReaderT
r n b -> n b Run (StateT
s) ~ forall n b.Monad
n =>StateT
s n b -> n (a, s) Run (WriterT
w) ~ forall n b. (Monad
n,Monoid
w) =>WriterT
w n b -> n (a, w) Run (RWST
r w s) ~ forall n b. (Monad
n,Monoid
w) =>RWST
r w s n b -> n (a, s, w)
This type is usually satisfied by the run
function of a transformer:
flip
runReaderT
:: r -> Run (ReaderT
r)flip
runStateT
:: s -> Run (StateT
s)runMaybeT
:: RunMaybeT
type RunDefault (t :: (Type -> Type) -> Type -> Type) (t' :: (Type -> Type) -> Type -> Type) = forall (n :: Type -> Type) b. Monad n => t n b -> n (StT t' b) #
A function like Run
that runs a monad transformer t
which wraps the
monad transformer t'
. This is used in defaultLiftWith
.
type RunDefault2 (t :: (Type -> Type) -> Type -> Type) (n :: (Type -> Type) -> Type -> Type) (n' :: (Type -> Type) -> Type -> Type) = forall (m :: Type -> Type) b. (Monad m, Monad (n' m)) => t m b -> m (StT n' (StT n b)) #
A function like Run
that runs a monad transformer t
which wraps the
monad transformers n
and n'
. This is used in defaultLiftWith2
.
class MonadBase b m => MonadBaseControl (b :: Type -> Type) (m :: Type -> Type) | m -> b where #
Writing instances
The usual way to write a
instance for a transformer
stack over a base monad MonadBaseControl
B
is to write an instance MonadBaseControl B B
for the base monad, and MonadTransControl T
instances for every transformer
T
. Instances for
are then simply implemented using
MonadBaseControl
, ComposeSt
, defaultLiftBaseWith
.defaultRestoreM
Associated Types
type StM (m :: Type -> Type) a #
Monadic state that m
adds to the base monad b
.
For all base (non-transformed) monads, StM m a ~ a
:
StMIO
a ~ a StMMaybe
a ~ a StM (Either
e) a ~ a StM [] a ~ a StM ((->) r) a ~ a StMIdentity
a ~ a StMSTM
a ~ a StM (ST
s) a ~ a
If m
is a transformed monad, m ~ t b
,
is the monadic state of
the transformer StM
t
(given by its StT
from MonadTransControl
). For a
transformer stack,
is defined recursively:StM
StM (IdentityT
m) a ~ComposeSt
IdentityT
m a ~ StM m a StM (MaybeT
m) a ~ComposeSt
MaybeT
m a ~ StM m (Maybe
a) StM (ErrorT
e m) a ~ComposeSt
ErrorT
m a ~Error
e => StM m (Either
e a) StM (ExceptT
e m) a ~ComposeSt
ExceptT
m a ~ StM m (Either
e a) StM (ListT
m) a ~ComposeSt
ListT
m a ~ StM m [a] StM (ReaderT
r m) a ~ComposeSt
ReaderT
m a ~ StM m a StM (StateT
s m) a ~ComposeSt
StateT
m a ~ StM m (a, s) StM (WriterT
w m) a ~ComposeSt
WriterT
m a ~Monoid
w => StM m (a, w) StM (RWST
r w s m) a ~ComposeSt
RWST
m a ~Monoid
w => StM m (a, s, w)
Methods
liftBaseWith :: (RunInBase m b -> b a) -> m a #
liftBaseWith
is similar to liftIO
and liftBase
in that it
lifts a base computation to the constructed monad.
Instances should satisfy similar laws as the MonadIO
and MonadBase
laws:
liftBaseWith . const . return = return
liftBaseWith (const (m >>= f)) = liftBaseWith (const m) >>= liftBaseWith . const . f
The difference with liftBase
is that before lifting the base computation
liftBaseWith
captures the state of m
. It then provides the base
computation with a RunInBase
function that allows running m
computations in the base monad on the captured state:
withFileLifted :: MonadBaseControl IO m => FilePath -> IOMode -> (Handle -> m a) -> m a withFileLifted file mode action = liftBaseWith (\runInBase -> withFile file mode (runInBase . action)) >>= restoreM -- = control $ \runInBase -> withFile file mode (runInBase . action) -- = liftBaseOp (withFile file mode) action
is usually not implemented directly, but using
liftBaseWith
.defaultLiftBaseWith
Construct a m
computation from the monadic state of m
that is
returned from a RunInBase
function.
Instances should satisfy:
liftBaseWith (\runInBase -> runInBase m) >>= restoreM = m
is usually not implemented directly, but using
restoreM
.defaultRestoreM
Instances
type RunInBase (m :: Type -> Type) (b :: Type -> Type) = forall a. m a -> b (StM m a) #
A function that runs a m
computation on the monadic state that was
captured by liftBaseWith
A RunInBase m
function yields a computation in the base monad of m
that
returns the monadic state of m
. This state can later be used to restore the
m
computation using restoreM
.
Example type equalities:
RunInBase (IdentityT
m) b ~ forall a.IdentityT
m a -> b (StM
m a) RunInBase (MaybeT
m) b ~ forall a.MaybeT
m a -> b (StM
m (Maybe
a)) RunInBase (ErrorT
e m) b ~ forall a.Error
e =>ErrorT
e m a -> b (StM
m (Either
e a)) RunInBase (ExceptT
e m) b ~ forall a.ExceptT
e m a -> b (StM
m (Either
e a)) RunInBase (ListT
m) b ~ forall a.ListT
m a -> b (StM
m [a]) RunInBase (ReaderT
r m) b ~ forall a.ReaderT
m a -> b (StM
m a) RunInBase (StateT
s m) b ~ forall a.StateT
s m a -> b (StM
m (a, s)) RunInBase (WriterT
w m) b ~ forall a.Monoid
w =>WriterT
w m a -> b (StM
m (a, w)) RunInBase (RWST
r w s m) b ~ forall a.Monoid
w =>RWST
r w s m a -> b (StM
m (a, s, w))
For a transformed base monad m ~ t b
, 'RunInBase m b' ~
.Run
t
type ComposeSt (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) a = StM m (StT t a) #
Handy type synonym that composes the monadic states of t
and m
.
It can be used to define the StM
for new MonadBaseControl
instances.
type RunInBaseDefault (t :: (Type -> Type) -> Type -> Type) (m :: Type -> Type) (b :: Type -> Type) = forall a. t m a -> b (ComposeSt t m a) #
A function like RunInBase
that runs a monad transformer t
in its base
monad b
. It is used in defaultLiftBaseWith
.
logError :: (HasCallStack, MonadLogger m) => Text -> m () #
See logDebug
Since: monad-logger-0.3.19
logInfo :: (HasCallStack, MonadLogger m) => Text -> m () #
See logDebug
Since: monad-logger-0.3.19
logErrorCS :: MonadLogger m => CallStack -> Text -> m () #
See logDebugCS
Since: monad-logger-0.3.19
logWarnCS :: MonadLogger m => CallStack -> Text -> m () #
See logDebugCS
Since: monad-logger-0.3.19
logInfoCS :: MonadLogger m => CallStack -> Text -> m () #
See logDebugCS
Since: monad-logger-0.3.19
class Monad m => MonadLogger (m :: Type -> Type) #
A Monad
which has the ability to log messages in some manner.
Instances
class (MonadLogger m, MonadIO m) => MonadLoggerIO (m :: Type -> Type) #
An extension of MonadLogger
for the common case where the logging action
is a simple IO
action. The advantage of using this typeclass is that the
logging function itself can be extracted as a first-class value, which can
make it easier to manipulate monad transformer stacks, as an example.
Since: monad-logger-0.3.10
Instances
data LoggingT (m :: Type -> Type) a #
Monad transformer that adds a new logging function.
Since: monad-logger-0.2.2
Instances
withInternalState :: (InternalState -> m a) -> ResourceT m a #
Run an action in the underlying monad, providing it the InternalState
.
Since 0.4.6
runInternalState :: ResourceT m a -> InternalState -> m a #
Unwrap a ResourceT
using the given InternalState
.
Since 0.4.6
getInternalState :: forall (m :: Type -> Type). Monad m => ResourceT m InternalState #
Get the internal state of the current ResourceT
.
Since 0.4.6
closeInternalState :: MonadIO m => InternalState -> m () #
Close an internal state created by createInternalState
.
Since 0.4.9
createInternalState :: MonadIO m => m InternalState #
Create a new internal state. This state must be closed with
closeInternalState
. It is your responsibility to ensure exception safety.
Caveat emptor!
Since 0.4.9
resourceForkIO :: forall (m :: Type -> Type). MonadUnliftIO m => ResourceT m () -> ResourceT m ThreadId #
Launch a new reference counted resource context using forkIO
.
This is defined as resourceForkWith forkIO
.
Note: Using regular forkIO
inside of a ResourceT
is inherently unsafe,
since the forked thread may try access the resources of the parent after they are cleaned up.
When you use resourceForkIO
or resourceForkWith
, ResourceT
is made aware of the new thread, and will only cleanup resources when all threads finish.
Other concurrency mechanisms, like concurrently
or race
, are safe to use.
If you encounter InvalidAccess
exceptions ("The mutable state is being accessed after cleanup"),
use of forkIO
is a possible culprit.
Since: resourcet-0.3.0
resourceForkWith :: forall (m :: Type -> Type) a. MonadUnliftIO m => (IO () -> IO a) -> ResourceT m () -> ResourceT m a #
Introduce a reference-counting scheme to allow a resource context to be shared by multiple threads. Once the last thread exits, all remaining resources will be released.
The first parameter is a function which will be used to create the
thread, such as forkIO
or async
.
Note that abuse of this function will greatly delay the deallocation of registered resources. This function should be used with care. A general guideline:
If you are allocating a resource that should be shared by multiple threads,
and will be held for a long time, you should allocate it at the beginning of
a new ResourceT
block and then call resourceForkWith
from there.
Since: resourcet-1.1.9
joinResourceT :: forall (m :: Type -> Type) a. ResourceT (ResourceT m) a -> ResourceT m a #
This function mirrors join
at the transformer level: it will collapse
two levels of ResourceT
into a single ResourceT
.
Since 0.4.6
runResourceTChecked :: MonadUnliftIO m => ResourceT m a -> m a #
Backwards compatible alias for runResourceT
.
Since: resourcet-1.1.11
resourceMask :: MonadResource m => ((forall a. ResourceT IO a -> ResourceT IO a) -> ResourceT IO b) -> m b #
Perform asynchronous exception masking.
This is more general then Control.Exception.mask
, yet more efficient
than Control.Exception.Lifted.mask
.
Since 0.3.0
Arguments
:: MonadResource m | |
=> IO a | allocate |
-> IO () | free resource |
-> m ReleaseKey |
Perform some allocation where the return value is not required, and automatically register a cleanup action.
allocate_
is to allocate
as bracket_
is to bracket
This is almost identical to calling the allocation and then
register
ing the release action, but this properly handles masking of
asynchronous exceptions.
Since: resourcet-1.2.4
Arguments
:: MonadResource m | |
=> IO a | allocate |
-> (a -> IO ()) | free resource |
-> m (ReleaseKey, a) |
Perform some allocation, and automatically register a cleanup action.
This is almost identical to calling the allocation and then
register
ing the release action, but this properly handles masking of
asynchronous exceptions.
Since 0.3.0
unprotect :: MonadIO m => ReleaseKey -> m (Maybe (IO ())) #
Unprotect resource from cleanup actions; this allows you to send resource into another resourcet process and reregister it there. It returns a release action that should be run in order to clean resource or Nothing in case if resource is already freed.
Since 0.4.5
release :: MonadIO m => ReleaseKey -> m () #
Call a release action early, and deregister it from the list of cleanup actions to be performed.
Since 0.3.0
register :: MonadResource m => IO () -> m ReleaseKey #
Register some action that will be called precisely once, either when
runResourceT
is called, or when the ReleaseKey
is passed to release
.
Since 0.3.0
type MonadResourceBase = MonadUnliftIO #
Just use MonadUnliftIO
directly now, legacy explanation continues:
A Monad
which can be used as a base for a ResourceT
.
A ResourceT
has some restrictions on its base monad:
runResourceT
requires an instance ofMonadUnliftIO
.MonadResource
requires an instance ofMonadIO
Note that earlier versions of conduit
had a typeclass ResourceIO
. This
fulfills much the same role.
Since 0.3.2
type InternalState = IORef ReleaseMap #
The internal state held by a ResourceT
transformer.
Since 0.4.6
transResourceT :: (m a -> n b) -> ResourceT m a -> ResourceT n b #
Transform the monad a ResourceT
lives in. This is most often used to
strip or add new transformers to a stack, e.g. to run a ReaderT
.
Note that this function is a slight generalization of hoist
.
Since 0.3.0
data ReleaseKey #
A lookup key for a specific release action. This value is returned by
register
and allocate
, and is passed to release
.
Since 0.3.0
data InvalidAccess #
Indicates either an error in the library, or misuse of it (e.g., a
ResourceT
's state is accessed after being released).
Since 0.3.0
Constructors
InvalidAccess | |
Fields |
Instances
Show InvalidAccess | |
Defined in Control.Monad.Trans.Resource.Internal Methods showsPrec :: Int -> InvalidAccess -> ShowS # show :: InvalidAccess -> String # showList :: [InvalidAccess] -> ShowS # | |
Exception InvalidAccess | |
Defined in Control.Monad.Trans.Resource.Internal Methods toException :: InvalidAccess -> SomeException # fromException :: SomeException -> Maybe InvalidAccess # displayException :: InvalidAccess -> String # |
data ResourceCleanupException #
Thrown when one or more cleanup functions themselves throw an exception during cleanup.
Since: resourcet-1.1.11
Constructors
ResourceCleanupException | |
Fields
|
Instances
Show ResourceCleanupException | |
Defined in Control.Monad.Trans.Resource.Internal Methods showsPrec :: Int -> ResourceCleanupException -> ShowS # show :: ResourceCleanupException -> String # showList :: [ResourceCleanupException] -> ShowS # | |
Exception ResourceCleanupException | |